#15953: Allow setting individual fields as 'unique' from the model Meta options
-------------------------------------+-------------------------------------
               Reporter:  julien     |          Owner:  nobody
                   Type:  New        |         Status:  new
  feature                            |      Component:  Database layer
              Milestone:             |  (models, ORM)
                Version:  1.3        |       Severity:  Normal
             Resolution:             |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |    Needs tests:  0
    Needs documentation:  0          |  Easy pickings:  0
Patch needs improvement:  0          |
-------------------------------------+-------------------------------------
Description changed by julien:

Old description:

> I'm dealing with this case:
>
> {{{#!python
> 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:
>
> {{{#!python
> 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:
>
> {{{#!python
> class B(models.Model):
>
>     class Meta:
>         unique = ('blah',)
> }}}

New description:

 I'm dealing with this case:

 {{{#!python
 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:

 {{{#!python
 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:

 {{{#!python
 class B(A):

     class Meta:
         unique = ('blah',)
 }}}

--

-- 
Ticket URL: <http://code.djangoproject.com/ticket/15953#comment:2>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to