Here's a simple relational pair of models.
class Shelf(models.Model):
name = models.CharField(max_length=100)
def has_books(self):
if Book.objects.filter(shelf=self):
return True
else:
return False
class Book(models.Model):
shelf = models.ForeignKey(Shelf)
name = models.CharField(max_length=100)
Is there a better (or alternative) way to write the "has_book" method?
I'm not a fan of the double database hit but I want to do this at the model level.