This code works well:

def detail(request, entity_group_id):
    entity_group = get_object_or_404(EntityGroup, pk=entity_group_id) # noqa
    entity_list = entity_group.members.order_by('name')
    context = {
        'entity_group': entity_group,
        'entity_list': entity_list,
    return render(request, 'core/detail.html', context)

When I converted it to a Generic View, a Reverse not found error occured

class DetailView(generic.DetailView):
    model = EntityGroup
    template_name = 'core/detail.html'

    def get_context_data(self, **kwargs):
        context = super(DetailView, self).get_context_data(**kwargs)
        context['entity_group'] = EntityGroup
        context['entity_list'] = EntityGroup.members
        return context

This is mu

class Entity(models.Model):
    is_person = models.BooleanField(default=True)
    person = models.ForeignKey(Person, on_delete=models.PROTECT, null=True) 
# noqa
    company = models.ForeignKey(Company, on_delete=models.PROTECT, 
null=True) # noqa
    name = models.CharField(max_length=30)

    def __str__(self):

    def title(self):

    class Meta:
        verbose_name_plural = 'entities'

class EntityGroup(models.Model):
    name = models.CharField(max_length=20)
    is_individual = models.BooleanField(default=True)
    members = models.ManyToManyField(Entity, through='Membership')

    def __str__(self):

    def title(self):

class Membership(models.Model):
    entity_group = models.ForeignKey(EntityGroup, on_delete=models.PROTECT, 
null=False) # noqa
    entity = models.ForeignKey(Entity, on_delete=models.PROTECT, null=False)

    def __str__(self):
        return + '-' +

    def title(self):
        return + '-' +

    class Meta:
        unique_together = ("entity", "entity_group")

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

Reply via email to