Reputation: 75973
Given this model:
from django.db import models
from django.contrib.auth.admin import User
# Create your models here.
class Plan(models.Model):
editors = models.ManyToManyField(User)
in which every plan can have more than one editor (User), how can I retrieve all plans for which a particular user is one of the editors?
Something like this?
Plan.objects.filter(editors__contains(request.user))
?
Upvotes: 1
Views: 506
Reputation: 599580
You just use the normal equals here.
Plan.objects.filter(editors=request.user)
Upvotes: 2