Hi,

I think you might want to use a common abstract base class. You want a 
completely separate database table for the two models, right?

Collin

On Wednesday, January 21, 2015 at 10:17:08 PM UTC-5, Samuel Jean wrote:
>
> Hi there, 
>
> Does anybody know of a way to trick Django 1.7 (or the proper way, if 
> any) to modify the property of an inherited field so that it has unique 
> property on the children only. 
>
> Consider this abstract model : 
>
> class UniqueObjectModel(models.Model): 
>      uuid = models.CharField(max_length=36, default=uuid4) 
>      pool = models.ForeignKey('Pool', related_name='+', to_field='uuid') 
>      ... 
>
>      class Meta: 
>          abstract = True 
>          unique_together = (('uuid', 'pool'),) 
>
> I would like the Pool model to inherit from UniqueObjectModel *but* have 
> its uuid field unique. 
>
> class Pool(UniqueObjectModel): 
>      def __init__(self, *args, **kwargs): 
>          super(Pool, self).__init__(*args, **kwargs) 
>          self._meta.get_field('pool').to = 'self' 
>          self._meta.get_field('uuid')._unique = True 
>
> However, Django still complains about Pool.uuid field not being unique. 
>
> $ python manage.py makemigrations myapp 
>
> CommandError: System check identified some issues: 
>
> ERRORS: 
> myapp.Controller.pool: (fields.E311) 'Pool.uuid' must set unique=True 
> because it is referenced by a foreign key. 
>
> Any ideas? 
>
> Thanks! 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f6a839e9-9140-4676-8649-530afde0881a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to