Thanks, Shawn!!!

Deeply appreciated!

-Carlos.

On Thu, Oct 1, 2009 at 10:38 AM, Shawn Milochik <shawn.m...@gmail.com>wrote:

>
>
> On Oct 1, 2009, at 9:25 AM, Carlos Gustavo wrote:
>
> >
> > Hi All,
> >
> > I am a django newbie and so far it has been great.
> >
> > How do I populate a mysql database table with data from a text file?
> >
> > Also How do I dump results of a database query into a text file.
> >
> > I have already created my django model for the mysql table.
> >
> > Thanks in advance.
> >
> > -Carlos
>
>
> To populate the database with the contents of a text file, write a
> script that imports your Django model, open the file (perhaps using
> the csv module, if it's a csv file), and iterate through the file,
> creating new instances of your model and saving them.
>
> Here's a barebones example I made by taking something I actually use
> and cutting out most of it so it's clear: http://pastebin.com/f651cf8de
>
> As for dumping the output of a query to a text file, that depends. The
> first thing that springs to mind is to write a method in the model
> which dumps the data you want in the format you want. So, for example,
> if your model has a csv_format(self) method, you could do the
> queryset, then iterate through it, writing instance.csv_format() to a
> text file.
>
> Shawn
>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to