I'm trying to make a new list of unused/unselected objects, so that I can show in the template what is used, and what is not used.
My model:
class Benefit(models.Model):
name = models.CharField(max_length=200)
class Profile(models.Model):
benefits = models.ManyToManyField(Benefit, blank=True, null=True, related_name="used_benefit")
My view:
class Profile(TemplateView):
template_name = "profile/benefits.html"
def get_context_data(self, **kwargs):
context = super(Profile, self).get_context_data(**kwargs)
context['unused_benefits'] = Profile.objects.exclude(pk__in=Profile.benefits.all())
return context
It is something Im not getting, because I get this error: 'ReverseManyRelatedObjectsDescriptor' object has no attribute 'all'
I have tried without all
, but then I get the error 'ReverseManyRelatedObjectsDescriptor' object is not itterable
Anyone see what I'm doing wrong?