Let's say users can make a list of Types. When they add to their list of types, a new UserType object is created with the User and the Type as ForeignKeys.
Other users can 'like' the individual types that a user has listed (UserTypes).
Given that I query for a user's UserTypes, how can I best get the number of UserLikes on each UserType in a QuerySet to use in a template? Would I simply loop through, query each and return the result as a separate list? That seems pretty messy.
class Type(model.Models):
name = models.CharField(max_length=100, blank=False)
description = models.TextField(max_length=1000, blank=True)
created_by = models.ForeignKey(User, blank=True, null=True, unique=False)
class UserType(model.Models):
user = models.ForeignKey(User, unique=False)
type = models.ForeignKey(Type, unique=False)
is_active = models.BooleanField(default=True)
class UserLike(model.Models):
user = models.ForeignKey(User, unique=False)
user_type = models.ForeignKey(UserType, unique=False)