我创建了两个继承模型条目的新类:
class Entry(models.Model):
LANGUAGE_CHOICES = settings.LANGUAGES
language = models.CharField(max_length=2, verbose_name=_('Comment language'), choices=LANGUAGE_CHOICES)
user = models.ForeignKey(User)
country = models.ForeignKey(Country, null=True, blank=True)
created = models.DateTimeField(auto_now=True)
class Comment(Entry):
comment = models.CharField(max_length=2000, blank=True, verbose_name=_('Comment in English'))
class Discount(Entry):
discount = models.CharField(max_length=2000, blank=True, verbose_name=_('Comment in English'))
coupon = models.CharField(max_length=2000, blank=True, verbose_name=_('Coupon code if needed'))
通过 admin.site.register 将这些新模型添加到管理员后,我在尝试通过管理员创建评论或折扣时收到 ValueError。添加条目工作正常。
错误信息:
/admin/reviews/discount/add/ 处的 ValueError 无法分配“''”:“Discount.discount”必须是“Discount”实例。请求方法:GET 请求 URL: http: //127.0.0.1 :8000/admin/reviews/discount/add/
异常类型:ValueError 异常值:
无法分配“''”:“Discount.discount”必须是“折扣”实例。异常位置:/Library/Python/2.6/site-packages/django/db/models/fields/related.py in set,第 211 行 Python 可执行文件:/usr/bin/python Python 版本:2.6.1