Here is my models,
class Age(models.Model):
layer = models.CharField(max_length=50)
order = models.PositiveIntegerField()
...
class Course(models.Model):
target_age = models.ManyToManyField('Age')
...
How can I get a course queryset including a specific age?
views:
request_courses = Course.objects.filter(target_age ...
Your question is a little vague. First, have a read of the documentation on querying across relationships.
If you want to get courses related to only those
Age‘s with a particular field value:where FIELD is the field in your
Agemodel you want to query against.Alternatively, if you have an
Ageobject and you want to get all courses that are actually related to a particularAgeobject, you need:or if you want to get courses that are related to at least one of a number of possible
Age‘s:EDIT
The last example is using the
inlookup