开发者

Django: Trying to organize django fixtures

开发者 https://www.devze.com 2023-04-10 13:04 出处:网络
I\'ve some models created wich i\'d like to provide initial data for. The problem is that there are several models, and i\'d like to organize the data.

I've some models created wich i'd like to provide initial data for. The problem is that there are several models, and i'd like to organize the data.

Currently, i've a big JSON file: initial_data.json with the data. I was thinking i could use some comments, but JSON has no comments! I really want to use json.

So, the file is like:

[
  {
    "model": "app1.Model1",
    "pk": 1,
    "fields": {
      "nombre": "A convenir con el vendedor"
    }
  },
//many more
开发者_如何学运维  {
    "model": "app2.Model1",
    "pk": 1,
    "fields": {
      "nombre": "A convenir con el vendedor"
    }
  },
//many more
  {
    "model": "app2.Model1",
    "pk": 1,
    "fields": {
      "nombre": "A convenir con el vendedor"
    }
  },
]

So, i thought i could organize them in different files, and with some initial script load them. The idea is not issue several python manage.py loaddata thisApp.Model But, then it would be difficult to separate the files that are not ment to be loaded at initial time.

Here are the files as example:

+app1
   +fixtures
      model1.json
      model2.json
+app2
   +fixtures
      model1.json
      model2.json
+app3
   +fixtures
      model1.json
      model2.json

Do you have any idea how to keep simple?


like you said, create several files, and write a script that combines them into initial_data.json and invokes the needed django.core.management command. this is what I do.


Call the files that contain initial data "initial_data.json" - syncdb will only load those. You can load the others manually with manage.py loaddata.

https://docs.djangoproject.com/en/dev/howto/initial-data/#automatically-loading-initial-data-fixtures

0

精彩评论

暂无评论...
验证码 换一张
取 消