Changes between Version 11 and Version 12 of Fixtures


Ignore:
Timestamp:
Jul 31, 2016, 11:00:01 AM (8 years ago)
Author:
Daniel Brotsky
Comment:

Update links to point to current docs; provide static as well as template analogy for namespacing.

Legend:

Unmodified
Added
Removed
Modified
  • Fixtures

    v11 v12  
    4949The location where Django loads a fixture from might seem unintuitive. As with template files, the fixtures of all applications in a project share the same namespace. If you follow [source:django/trunk/django/core/management/commands/loaddata.py?rev=9770#L79 loaddata.py] you see that Django searches for {{{ *appnames*/fixtures }}} and {{{ settings.FIXTURE_DIRS }}}  and loads the first match. So if you use names like {{{ testdata.json }}} for your fixtures you must make sure that no other active application uses a fixture with the same name. If not, you can never be sure what fixtures you actually load.
    5050
    51 Therefore it is suggested that you qualify your fixtures with the name of the associated application.  One strategy for this is to use the application name as a filename prefix, as in {{{myapp/fixtures/myapp_testdata.json}}}.  Another strategy, which is consistent with that recommended for templates in the Django tutorial, is to put your application fixtures in a application-named subdirectory, as in {{{myapp/fixtures/myapp/testdata.json}}}.  Both of these conventions work well with {{{loaddata}}}.
     51Therefore it is suggested that you qualify your fixtures with the name of the associated application.  One strategy for this is to use the application name as a filename prefix, as in {{{myapp/fixtures/myapp_testdata.json}}}.  Another strategy, which is consistent with that recommended for templates and static files in the Django documentation, is to put your application fixtures in a application-named subdirectory, as in {{{myapp/fixtures/myapp/testdata.json}}}.  Both of these conventions work well with {{{loaddata}}}.
    5252
    5353
    54 Links:
    55 [http://en.wikipedia.org/wiki/JSON]
    56 [http://www.djangoproject.com/documentation/models/fixtures/]
    57 [http://www.djangoproject.com/documentation/testing/#fixtures]
    58 [https://docs.djangoproject.com/en/1.9/intro/tutorial03/]
     54Links: \\
     55[http://en.wikipedia.org/wiki/JSON] \\
     56[https://docs.djangoproject.com/en/1.9/howto/initial-data/] \\
     57[https://docs.djangoproject.com/en/1.9/topics/testing/tools/#fixture-loading] \\
     58[https://docs.djangoproject.com/en/1.9/intro/tutorial03/] \\
     59[https://docs.djangoproject.com/en/1.9/howto/static-files/]
Back to Top