My expectation is something like this:-
class watchlist(models.Model):
currently_watching = all_movies_in_currently_watching
on_hold = all_movies_in_on_hold
planning_to_watch = all_movies_in_planning_to_watch
completed = all_movies_in_completed
models.py:-
from django.db import models
from django.core.validators import MinValueValidator, MaxValueValidator
from django.contrib.auth.models import User
# Create your models here.
class Tag(models.Model):
name = models.CharField(max_length=55)
def __str__(self):
return self.name
class Movie(models.Model):
title = models.CharField(max_length=255)
release_year = models.PositiveIntegerField(validators=[
MinValueValidator(1900),
MaxValueValidator(2100),
])
duration_in_min = models.PositiveSmallIntegerField()
imdb_rating = models.DecimalField(max_digits=2, decimal_places=1)
rotten_tomatoes_score = models.PositiveSmallIntegerField(validators=[
MinValueValidator(1),
MaxValueValidator(100)
])
cover_img = models.ImageField(upload_to="cover_images")
tags = models.ManyToManyField(Tag)
def __str__(self):
return self.title
I would set this up with a Watchlist like this:
class Watchlist(Model):
list_name = CharField(...)
This model would have 4 entries, one for each category.
Then, your Movie
model would have a foreign key to Watchlist
, the entry identifying which list it was in.
2 Likes
cehceh
June 29, 2023, 12:01pm
3
I think you can make your class WatchList(models.Model):
As follows in one of the two ways (I preferred the second way):
class WatchList(models.Model):
MY_LIST=(
("", "Choose One Of The Following Plan"),
("current", "Currently Watching"),
("hold", "On Hold"),
("plan", "Plan To Watch"),
("completed", "Completed"),
)
category = models.CharField(max_length=15, choices=MY_LIST)
You can use it in your views as
current_watching = WatchList.objects.filter(category="current")
The second way is :
MY_LIST=(
(0, "Choose One Of The Following Plan"),
(1, "Currently Watching"),
(2, "On Hold"),
(3, "Plan To Watch"),
(4, "Completed"),
)
currently_watching = models.IntegerField(
default=0,
choices=MY_LIST,
)
you can use it in views as follows:
current_watching = WatchList.objects.filter(category=1)
on_hold = WatchList.objects.filter(category=2)
plan_to_watch = WatchList.objects.filter(category=3)
completed = WatchList.objects.filter(category=4)
and you must take in your consideration what Ken said about the ForeignKey
Hope it helps
1 Like