This code in my works fine when it was still not in template format

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 changed it into a Generic View a NoReverseMatch comes up...

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

Here is my

class Entity(models.Model):
    name = models.CharField(max_length=30)

class EntityGroup(models.Model):
    name = models.CharField(max_length=20)
    members = models.ManyToManyField(Entity, through='Membership')
class Membership(models.Model):
    entity_group = models.ForeignKey(EntityGroup, on_delete=models.PROTECT, 
    entity = models.ForeignKey(Entity, on_delete=models.PROTECT, null=False)

How do I set a reverse on the Generic view?

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