So I am new to Django, and want to describe the scenario: there are a bunch of Persons
, and there are a bunch of Items
, and a person passes Items
to another Person
.
I have the following model:
class Item(models.Model):
title = models.CharField(max_length=1024, blank=False)
def __unicode__(self):
return self.title
class Person(models.Model):
name = models.CharField(max_length=127, blank=False)
out_item = models.ManyToManyField(
Item,
through='Event',
through_fields=('from_user', 'item'),
related_name='giver'
)
in_item = models.ManyToManyField(
Item,
through='Event',
through_fields=('to_user', 'item'),
related_name='receiver'
)
def __unicode__(self):
return self.name
class Event(models.Model):
item = models.ForeignKey(Item)
from_user = models.ForeignKey(Person, related_name='event_as_giver')
to_user = models.ForeignKey(Person, related_name='event_as_receiver')
But makemigrations
tells me app.Person: (models.E003) The model has two many-to-many relations through the intermediate model 'app.Event'.
I wonder what I did wrong? Or what is a clean way to achieve the scenario? Perhaps I can separate Event
into GiveEvent
and ReceiveEvent
? But that just makes less sense intuitively, since there is actually only a single event when item is passed.