Django Model Field With Secondary Field
I am trying to create a user sign up form in Django that allows for a primary field with an associated integer field. I need each user to be able to select a genre (for movies), an
Solution 1:
A good way to do this could be to use a through model linking the user with the genre, keeping track of how much the user likes that genre within that model instead of within the Genre model since the "like" percent depends on the connection with the user.
So you could have a class that looks something like:
classLike(models.Model): # name this model something better than "Like"
user = models.ForeignKey(User, related_name="liked_genres")
genre = models.ForeignKey(Genre, related_name="user_ratings")
rating = models.IntegerField()
This will also mean that a user can like several genres instead of having just one.
Post a Comment for "Django Model Field With Secondary Field"