This code in my views.py 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 models.py

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, 
null=False)
    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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c2412652-22e2-41d4-874f-ff180e36c01d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to