tkhyn / django-gm2m

MIT License
35 stars 23 forks source link

AttributeError: 'User' object has no attribute 'event_set' #59

Closed Mariownyou closed 2 years ago

Mariownyou commented 2 years ago

Can't get all events related to events related to m2m field I added user instance to links I can get user from event.links.all() But I can't get all events for user. user.event_set is not working

class Event(models.Model):
    links = GM2MField(through='EventThrough', blank=True)

class EventThrough(models.Model):
    event = models.ForeignKey(EventLog, on_delete=models.CASCADE, db_index=True)
    object = GenericForeignKey(ct_field='content_type', fk_field='object_id')
    content_type = models.ForeignKey("contenttypes.ContentType",
                                     on_delete=models.CASCADE, db_index=True)
    object_id = models.CharField(max_length=255)  # rename to object_id