[Django] #23779: Can't use unique_together if one of the fields is in a mixin

77 views
Skip to first unread message

Django

unread,
Nov 7, 2014, 10:27:33 AM11/7/14
to django-...@googlegroups.com
#23779: Can't use unique_together if one of the fields is in a mixin
----------------------------------------------+--------------------
Reporter: knyghty | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.7
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
Slightly related to https://code.djangoproject.com/ticket/16732

I have a mixin:


{{{
class PublishableMixin(object):
publish_date = models.DateTimeField()
}}}


and a model I wish to use it in:


{{{
class Article(PublishableMixin, models.Model):
slug = models.SlugField()

class Meta:
unique_together = ('publish_date', 'slug')
}}}

This fails at the system check level:

news.Article: (models.E012) 'unique_together' refers to the non-existent
field 'publish_date'.

--
Ticket URL: <https://code.djangoproject.com/ticket/23779>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 7, 2014, 10:33:44 AM11/7/14
to django-...@googlegroups.com
#23779: Can't use unique_together if one of the fields is in a mixin
-------------------------------------+-------------------------------------
Reporter: knyghty | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 1.7
(models, ORM) | Resolution: invalid
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* status: new => closed
* needs_docs: => 0
* resolution: => invalid
* needs_tests: => 0
* needs_better_patch: => 0


Comment:

You need to use abstract models as described
[https://docs.djangoproject.com/en/dev/topics/db/models/#model-inheritance
in the documentation] (not inherit from `object`). If something isn't
clear there about that, could you open a documentation ticket? Thanks!

--
Ticket URL: <https://code.djangoproject.com/ticket/23779#comment:1>

Reply all
Reply to author
Forward
0 new messages