skip to Main Content

Postgresql – How to annotate django queryest using subquery where that subquery returns list of ids from related model records

I have one database model, let's say ModelA: class ModelA(models.Model): field_1 = models.ManyToManyField( "core.ModelB", blank=True ) user = models.ForeignKey("core.User", on_delete=models.CASCADE) type = models.CharField(choices=ModelATypes.choices) The field_1 of ModelA is a many to many field that references ModelB. class ModelB(models.Model): uid =…

VIEW QUESTION

Postgresql – How to query a Django (DRF) model to get it with other model data attached?

I have a Post model: class Post(models.Model): profile = models.ForeignKey(Profile, related_name="posts", on_delete=CASCADE) project = models.ForeignKey(Project, related_name="posts", on_delete=CASCADE) title = models.CharField(verbose_name="Title", max_length=150) body = models.TextField(verbose_name="Content", max_length=1300) image_url = models.URLField(max_length=256, null=True, blank=True) liked_by = models.ManyToManyField(Profile, related_name="post_likes") date_published = models.DateTimeField(auto_now_add=True, verbose_name="Date published") date_modified…

VIEW QUESTION
Back To Top
Search