I need to set up one-to-one relation which must also be generic. May be you can advice me a better design. So far I came up to the following models
class Event(models.Model):
# skip event related fields...
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_type', 'object_id')
class Meta:
unique_together = ('content_type', 'object_id')
class Action1(models.Model):
# skip action1 related fields...
events = generic.GenericRelation(Event, content_type_field='content_type', object_id_field='object_id')
@property
def event(self):
return self.events.get() # <<<<<< Is this reasonable?
class Action2(models.Model):...
In Django Admin in event list I want to collect all actions, and from there I want go to admin pages for actions. Is it possible to avoid creating event
property in the action models? Is there a better solution? It would be nice to combine the field events
and the property event
in a single definition. The project I am working with uses Django 1.1