ValueError with multi-table inheritance in Django Admin

Posted by jorde on Stack Overflow See other posts from Stack Overflow or by jorde
Published on 2010-05-15T14:02:15Z Indexed on 2010/05/15 14:04 UTC
Read the original article Hit count: 405

I created two new classes which inherit model 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'))

After adding these new models to admin via admin.site.register I'm getting ValueError when trying to create a comment or a discount via admin. Adding entries works fine.

Error msg:

ValueError at /admin/reviews/discount/add/ Cannot assign "''": "Discount.discount" must be a "Discount" instance. Request Method: GET Request URL: http://127.0.0.1:8000/admin/reviews/discount/add/ Exception Type: ValueError Exception Value:
Cannot assign "''": "Discount.discount" must be a "Discount" instance. Exception Location: /Library/Python/2.6/site-packages/django/db/models/fields/related.py in set, line 211 Python Executable: /usr/bin/python Python Version: 2.6.1

© Stack Overflow or respective owner

Related posts about django

Related posts about django-admin