Tuesday, April 3, 2012

Model validation fails, when inherited model redeclare parent field

Hello!

In our apps (that use Django 1.2.7) we use following models:

class BaseRegistration(models.Model):
exhibition = models.ForeignKey(...)
year = models.IntegerField(...)
user = models.ForeignKey('auth.User')

class BarcodeRegistration(BaseRegistration):
class Meta:
abstract = True

class EventRegistration(BarcodeRegistration):
event = models.ForeignKey(...)

I append *validate_unique* by *user* and *event* fields in
EventRegistration class:

class EventRegistration(BarcodeRegistration):
event = models.ForeignKey(...)
user = models.ForeignKey('auth.User')

class Meta:
unique_together = ('event', 'user')

But in django command manage.py validate fails with error:

exhibition.eventregistration: "unique_together" refers to user. This
is not in the same model as the unique_together statement.

After some "pdb'ing" of django.core.management.validation,
django.db.models.base, and django.db.models.options I found, that is
happend because:

In [13]: EventRegistration._meta.get_field('user') in
EventRegistration._meta.parents.keys()[0]._meta.local_fields
Out[13]: True

In [14]: EventRegistration._meta.get_field('user') in
EventRegistration._meta.local_fields
Out[14]: False

Is it's something wrong with our code?

Thanks

--
Shavrin Ivan

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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate