1
如何为包含外键和日期时间字段的django模型提供初始数据。如何向django模型提供初始数据?
例如::
仲裁/ models.py
class Question(models.Model):
user=models.ForeignKey(User)
created=models.DateTimeField(auto_now_add=True)
question=models.TextField()
tags=models.CharField(max_length=50)
仲裁/装置/ questions.json
[
{
"model": "quorum.question",
"pk": 1,
"fields": {
"question": "what is cryptography in computer science?",
"tags": "computer science, cryptography."
}
},
{
"model": "quorum.question",
"pk": 2,
"fields": {
"question": "How python language got name? from snake? is it from monty python circus performence(the projectile stuff)?",
"tags": "python"
}
}
]
尝试[dumpdata(HTTPS://docs.djangoproject。 com/en/dev/ref/django-admin /#dumpdata-appname-appname-appname-model)和['loaddata'](https://docs.djangoproject.com/en/dev/ref/django-admin/ #loaddata-fixture-fixture) – yuwang
使用'dumpdata --indent = 4 --natural'来了解如何为外键设置夹具。为日期时间字段使用字符串,例如“2013-01-01T00:00” –