in terms of how we're using the product. (Disclaimer: I'm relatively
new to Django, and extremely new to the codebase that I ran into this
on).
We've got a form of schema-inheritance going on in this project in
order to accomplish shared-id-space and the ability to relate models
to one of a number of different types. The way that we've broken it
out runs us into a strange inconsistency in Django that specifically
affects our ability to serialize the objects. Here's a simplified
version of what we're doing:
class Entity(models.Model):
entityType = models.CharField(editable=False,max_length=50)
def __init__(self, *args, **kwargs):
super(Entity, self).__init__(*args, **kwargs)
self.entityType = self.__class__.__name__
def __unicode__(self):
return 'Entity: %s %s' %(self.entityType, self.id)
class BasePerson(Entity):
entity = models.OneToOneField(Entity, parent_link=True)
name = models.CharField(max_length=50)
class Meta:
abstract = True
class Kid(BasePerson):
school = models.CharField(max_length=50)
class Adult(BasePerson):
job = models.CharField(max_length=50)
When I dump instances of these models out using the standard fixtures
serialization, instances of Kid will serialize the 'entity' field, but
instances of Adult won't. The reason is because Adult's entity field
is marked primaryKey=True. Kid's is not. There appears to be a caching
issue here, because if I swap the order that Kid and Adult are defined
in.. the error reverses (now Kid's field will be marked pk).
Is this a bug? If not, what's the reasoning behind this behavior? Is
there a better pattern for accomplishing this kind of inheritance?
Thanks in advance for your help.
Phill
--
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.
No comments:
Post a Comment