Opened 15 years ago
Last modified 14 years ago
#15953 closed New feature
Allow setting individual fields as 'unique' from the model Meta options — at Initial Version
| 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
I'm dealing with this case:
class A(models.Model): blah = models.CharField(max_length=100) class Meta: abstract = True class B(models.Model): 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(models.Model): 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(models.Model): class Meta: unique = ('blah',)
Note:
See TracTickets
for help on using tickets.