我有一个带有“发布”模型的 Django 博客,如下所示:
class Post(models.Model):
title = models.CharField(max_length=1000)
author = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
text = models.TextField(max_length=10000)
CATEGORY_CHOICES = (
('breakfast','Breakfast'),
('brunch','Brunch'),
...
)
category = models.CharField(max_length=100,blank=True,choices=CATEGORY_CHOICES)
我已使用该命令将一堆“发布”对象(已完成上述所有字段)上传到我的数据库python manage.py loaddata fixturename.json
。但是,当我登录管理站点以修改对象时,我为“类别”字段上传的值不会显示为字段下拉列表中的预选值。为什么是这样?有什么办法可以解决吗?
编辑:这是我的 json 夹具文件中的片段:
{
"pk": 34,
"model": "blogs.post",
"fields": {
"category": "breakfast",
"author": "jennaboller",
"text": "I have to say, my favorite weekend breakfast is blah blah blah",
"title": "Corned Beef Hash & Eggs: My Favorite Weekend Breakfast",
"pub_date": "2011-01-25 05:05:37"
}