0

Im trying to output all the events that a member is one of the sponsors and speakers of that event. Using member.event_set.all works fine for members that were event speakers. But if I use member.msponsor_set.all for members that were event sponsors nothing is returned.

Here is my event model...

class Event(models.Model):
    member_speaker = models.ManyToManyField(Member)
    member_sponsor = models.ManyToManyField(Member, related_name='msponsor')
  • 1
    Can you post the whole Event model? – Sanip Feb 19 '19 at 06:44
  • 1
    Please share the whole event model as well as the Member model – amulya349 Feb 19 '19 at 06:52
  • By setting `related_name` you’re replacing the default `_set` conventions for the `RelatedManager` you have to do this in this case since both relationships are pointing to the same model. A better naming would have been `related_name=sponsored_events` so the related query would read `member.sponsored_events.all()` (note it’s plural and it described the model on which it’s defined not the model to which the field refers to). – dirkgroten Feb 19 '19 at 08:51
  • Do you really mean that the member has to be a sponsor *and* a speaker? – Bernhard Vallant Feb 19 '19 at 09:46
  • followed the suggestion of @dirkgroten and boom it worked. Thanks man, I should have named it better xD – Nthnyvllflrs Feb 19 '19 at 23:37

1 Answers1

2

Don't know what the set is used for but doing

member.msponsor.all()

can give you all the events data related to that sponsor.

Sanip
  • 1,772
  • 1
  • 14
  • 29