Answer the question
In order to leave comments, you need to log in
How to correctly select a record from a database with an exact set of relationships?
For example:
# models.py
class Tag(models.Model):
name = models.CharField()
content = models.ManyToManyField('Content', through='TagContent')
class Content(models.Model):
title = models.CharField()
description = models.TextField()
tags = models.ManyToManyField('Tag', through='TagContent')
class TagContent(models.Model):
tag = models.ForeignKey('Tag', on_delete=models.CASCADE)
content = models.ForeignKey('Content', on_delete=models.CASCADE)
Content.objects.filter(tags__id=1)
Answer the question
In order to leave comments, you need to log in
Try it through the get method, I don’t know for sure, I didn’t even remember about django for 2 years. And so, in the docs, I think it's not difficult to find the answer to your question https://docs.djangoproject.com/en/3.2/topics/db/models/ . There should not be a question, the answer to which can be obtained by reading the technology documentation.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question