Opened 14 years ago

Closed 14 years ago

#14124 closed (invalid)

Cannot use a proxy model with unique_together

Reported by: mlhamel Owned by: nobody
Component: Uncategorized Version: 1.2
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Karen Tracey)

I've just used a proxy model in my own custom application and i've just found a small problem. Right now, to be able to create a Proxy model, i'm force to redefine a Meta options like that:

class NewDiscount(Discount):
    class Meta:
        proxy = True

The problem i have is that the original discount object defined the following Meta options:

class Discount(models.Model):
    class Meta:
        verbose_name = _("Discount")
        verbose_name_plural = _("Discounts")
        unique_together = ('slug', 'amount')

Since i've overwritten the Meta class I should copy the original Meta options inside my Proxy model like that:

class NewDiscount(Discount):
    class Meta:
        proxy = True
        verbose_name = _("Discount")
        verbose_name_plural = _("Discounts")
        unique_together = ('slug', 'amount')

But, when I'm doing that, Django throw me an error saying:

"store.discount: "unique_together" refers to site. This is not in the same model as the unique_together statement."

Change History (1)

comment:1 by Karen Tracey, 14 years ago

Description: modified (diff)
Resolution: invalid
Status: newclosed

Fixed formatting. Please use WikiFormatting and use Preview before submitting.

Why do you think you have to copy the Meta class wholesale? Given that unique_together affects the database table definitions, and proxy models are intended to simply change Python behavior while using the database table from the proxied model, it does not make sense to copy unique_together into the proxy model. So, what problem do you encounter if you do not attempt to set unique_together in the proxy model? That would be a problem to investigate and fix, if there is one. For now closing this as invalid since the described behavior appears correct to me.

Note: See TracTickets for help on using tickets.
Back to Top