Opened 13 years ago

Last modified 13 years ago

#15953 closed New feature

Allow setting individual fields as 'unique' from the model Meta options — at Version 1

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 Julien Phalip)

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(models.Model):

    class Meta:
        unique = ('blah',)

Change History (1)

comment:1 by Julien Phalip, 13 years ago

Description: modified (diff)

(fixed description: B inherits from A)

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