Changes between Initial Version and Version 1 of Fixtures

10/07/07 08:14:28 (15 years ago)
Lolka <alexanderad@…>

Very simple example of fixtures


  • Fixtures

    v1 v1  
     1''It is very simple example, please, read something more complex if you need.''
     3Fixtures are very powerful to play with your database sample data during development process.
     4After each '''python reset <myapp>''' command you need to populate database with sample data again and again using admin interface. It's quite boring, isn't it?
     5With fixtures our life became more comfortable and easy. Look at this example.
     6Lets imagine that you have some data in db, so we can dump it. Even if your models have ForeignKeys or any kind of *To* relations.
     8First we need to define fixtures dir in settings file:
     11FIXTURE_DIRS = (
     12   '/path/to/myapp/fixtures/',
     16Lets dump our data:
     19cd /path/to/myapp/fixtures
     20python dumpdata --format=json myapp > initial_data.json
     26python reset myapp
     28You have requested a database reset.
     29This will IRREVERSIBLY DESTROY any data for
     30the "myapp" application in the database "mydb".
     31Are you sure you want to do this?
     33Type 'yes' to continue, or 'no' to cancel: yes
     36Now we have clean DB, lets populate it with our sample data:
     39python syncdb
     40Loading 'initial_data' fixtures...
     41Installing json fixture 'initial_data' from '/path/to/myapp/fixtures/'.
     42Installed 24 object(s) from 1 fixture(s)
Back to Top