I am looking to solve this optimally using Django Query Set.
Each library can have one and only one book.
Several libraries can have multiple instances of the same book (i.e.: Library1 can have an instance of “Girl with the Dragon Tattoo” and Library4 can have another instance of “Girl with the Dragon Tattoo”)
Book(models.Model):
name = models.CharField(max_length=30)
Library(models.Model):
book = models.ForeignKey(Book) # multiple libraries have the book
city = models.CharField(max_length=50)
So how would I find a book that is in less than 3 libraries?
Use
annotateandCount.