Samuel Jean
unread,Jan 22, 2015, 3:17:08 AM1/22/15Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to django...@googlegroups.com
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!