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/54C0568F.8080707%40herness.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to