Re: Best way to keep populating database after creation?

2009-12-22 Thread Kevin L
I should've Googled before speaking. According to
http://stackoverflow.com/questions/1499898/django-create-fixtures-without-specifying-a-primary-key
by using "pk: null" in fixtures, the primary key will be automatically
assigned when saving the object. Great! I'll still do some
benchmarking for fun.

On Dec 22, 2:06 pm, Kevin L  wrote:
> Ahh, I had seen that earlier but disregarded it because it pertained
> to CSV files. I see and am reminded now that I can import my project
> or app into a python script. My models won't be changing which would
> seem to make a good case for fixtures, but at least this way I don't
> need to worry about primary keys because of Django's ORM being used.
> I'll have to benchmark both approaches and unless fixtures is
> extremely faster, I'll probably use a script for the abstraction.
>
> Thanks Shawn!
>
> On Dec 22, 1:43 pm, Shawn Milochik  wrote:
>
>
>
> > Well, the data loaded by fixtures will remain, so if you need to add new 
> > data you'll just have to create and load a fixture with the new data.
>
> > It's easy to convert data to JSON or whatever, especially if your input 
> > isn't going to change.
>
> > However, it seems like maybe you want something else altogether. If you are 
> > going to be dumping data periodically into a flat file, and then want to 
> > import it, then I'd use a script that can read that data and create and 
> > save new instances of your models.
>
> > Here's a quick & dirty example I put up to illustrate this. It imports from 
> > a CSV, but you can easily adapt it.http://pastebin.com/f651cf8de
>
> > 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-us...@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.




Re: Best way to keep populating database after creation?

2009-12-22 Thread Kevin L
Ahh, I had seen that earlier but disregarded it because it pertained
to CSV files. I see and am reminded now that I can import my project
or app into a python script. My models won't be changing which would
seem to make a good case for fixtures, but at least this way I don't
need to worry about primary keys because of Django's ORM being used.
I'll have to benchmark both approaches and unless fixtures is
extremely faster, I'll probably use a script for the abstraction.

Thanks Shawn!

On Dec 22, 1:43 pm, Shawn Milochik  wrote:
> Well, the data loaded by fixtures will remain, so if you need to add new data 
> you'll just have to create and load a fixture with the new data.
>
> It's easy to convert data to JSON or whatever, especially if your input isn't 
> going to change.
>
> However, it seems like maybe you want something else altogether. If you are 
> going to be dumping data periodically into a flat file, and then want to 
> import it, then I'd use a script that can read that data and create and save 
> new instances of your models.
>
> Here's a quick & dirty example I put up to illustrate this. It imports from a 
> CSV, but you can easily adapt it.http://pastebin.com/f651cf8de
>
> 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-us...@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.




Re: Best way to keep populating database after creation?

2009-12-22 Thread Shawn Milochik
Well, the data loaded by fixtures will remain, so if you need to add new data 
you'll just have to create and load a fixture with the new data.

It's easy to convert data to JSON or whatever, especially if your input isn't 
going to change.

However, it seems like maybe you want something else altogether. If you are 
going to be dumping data periodically into a flat file, and then want to import 
it, then I'd use a script that can read that data and create and save new 
instances of your models.

Here's a quick & dirty example I put up to illustrate this. It imports from a 
CSV, but you can easily adapt it.
http://pastebin.com/f651cf8de

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-us...@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.




Re: Best way to keep populating database after creation?

2009-12-22 Thread Kevin L
Hi Shawn,
I had already looked at fixtures and the reason I disregarded it is
because the documentation says:

"Every time you run loaddata the data will be read from the fixture
and re-loaded into the database. Note that this means that if you
change one of the rows created by a fixture and then run loaddata
again you'll wipe out any changes you've made."

So, it seems that means one of two things. Either I'll have to keep a
single fixture, which on every update just gets longer, or a directory
full of arbitrarily named fixtures (for uniqueness). Both, I'd like to
avoid. I guess this depends on whether it's necessary to retain each
fixture permanently after import. Do you know this?

I'd be fine with a solution that necessitates a fixture for import but
then would allow me to delete it immediately afterwards (irregardless
of backup practices).

Also, my data won't be in YAML or JSON. Does MySQL or Sqlite offer an
export option that'll do this?

Thanks and sorry if all of this is common knowledge for everyone else.

Kevin

On Dec 22, 12:13 pm, Shawn Milochik  wrote:
> Fixtures sound like the way to go.
>
> You should get what you need from 
> here:http://docs.djangoproject.com/en/dev/howto/initial-data/
>
> 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-us...@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.




Re: Best way to keep populating database after creation?

2009-12-22 Thread Hinnack
you could use a migration tool like this:
http://south.aeracode.org/

and do some data migration...

--

Hinnack

2009/12/22 Kevin L 

> Hi, could anyone offer some tips as to the best way to keep populating
> my Django database after it's finalized (schema-/model-wise)? The app
> is most read-only and periodically, I finish up a new data set that
> needs to be included. How do I add this additional data set into the
> database without wrecking it? Right now, it seems like a combination
> of manage.py's sqlcustom and a python script to auto-create a .sql
> file for me is my best bet. Thanks in advance.
>
> Btw, data entry in the admin is not an option.
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>
>

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.




Re: Best way to keep populating database after creation?

2009-12-22 Thread Shawn Milochik
Fixtures sound like the way to go.

You should get what you need from here:
http://docs.djangoproject.com/en/dev/howto/initial-data/

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-us...@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.




Best way to keep populating database after creation?

2009-12-22 Thread Kevin L
Hi, could anyone offer some tips as to the best way to keep populating
my Django database after it's finalized (schema-/model-wise)? The app
is most read-only and periodically, I finish up a new data set that
needs to be included. How do I add this additional data set into the
database without wrecking it? Right now, it seems like a combination
of manage.py's sqlcustom and a python script to auto-create a .sql
file for me is my best bet. Thanks in advance.

Btw, data entry in the admin is not an option.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.