Opened 14 years ago
Last modified 13 years ago
#15953 closed New feature
Allow setting individual fields as 'unique' from the model Meta options — at Version 2
Reported by: | Julien Phalip | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.3 |
Severity: | Normal | Keywords: | |
Cc: | jonas-django@… | Triage Stage: | Design decision needed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
I'm dealing with this case:
class A(models.Model): blah = models.CharField(max_length=100) class Meta: abstract = True class B(A): pass
... where A
is in a separate app than B
and is used in multiple different contexts. I need to have the blah
field be unique for B
, whereas it shouldn't necessarily be unique in every other context where it is used. The only way I've found so far is:
class B(A): pass B._meta.get_field('blah')._unique = True # Ugliness alert!
Is it envisageable to allow setting the unique
flag for individual fields from the Meta options, in the same way as with unique_together
? Something like this for example:
class B(A): class Meta: unique = ('blah',)
Change History (2)
comment:1 by , 14 years ago
Description: | modified (diff) |
---|
comment:2 by , 14 years ago
Description: | modified (diff) |
---|
Note:
See TracTickets
for help on using tickets.
(fixed description:
B
inherits fromA
)