I am trying to build an extra field in a Django query to specify whether an article belongs to a Journal.
I am trying to do something like Article.objects.filter(title__icontains='foo').extra(select={in_the_journal:Function_Belongs_To_Journal(journal_id)})
I am currently iterating the search results to find that out but I'd rather like to retrieve this info from the database already
My models.py
are as follows:
class Article(models.Model):
title = models.CharField(max_length=400)
content = models.TextField()
date = models.DateTimeField('date published', null=True, default = timezone.now())
class Journal(models.Model):
name = models.CharField(max_length=200)
authors = models.ManyToManyField(Author, null=True, blank = True)
articles = models.ManyToManyField(Article, null=True, blank = True)
Is that a way to add an extra field to indicate that? Either using extra or annotate Django tags?