I have two models:
class BookSeries(models.Model):
title = models.CharField(max_length=200, null=False, blank=False, unique=True)
#extra fields
class Book(models.Model):
series = models.ForeignKey(BookSeries, blank=True, null=True, default=None)
publisher = models.ForeignKey(Publisher, default=None, null=True, blank=True)
title = models.CharField(max_length=200, null=False, blank=False, unique=True)
#extra fields
Now I want to query all the books which doesn't belong to a series and only one of any of the book which belong to the same series (series can be null).
Problem statement:
I wan to query all the individual books and series. Since a series can have multiple books, and a book may not belong to a series. One of the solutions is to query all the book objects ( which doesn't belong to a series) and query all the series objects as described here. But this would give all series together and books together in the response. I don't want them to be grouped together (I am also using pagination).
something like : Book.objects.filter( disctinct only if(series is not None))
I thought of using distinct and exclude but couldn't make it work.