我创建了两个继承自模型Entry的新类:
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。添加条目没有问题。
错误消息:
ValueError at /admin/reviews/discount/add/
无法分配“''”:“Discount.discount”必须是“Discount”实例。
请求方法:GET
请求URL:http://127.0.0.1:8000/admin/reviews/discount/add/
异常类型:ValueError
异常值:
无法分配“''”:“Discount.discount”必须是“Discount”实例。
异常位置:/Library/Python/2.6/site-packages/django/db/models/fields/related.py in set, line 211
Python可执行文件:/usr/bin/python
Python版本:2.6.1