Hello, I have an issue with Django models
I have a model Movie -
title = models.CharField(max_length = 200)
director = models.CharField(max_length = 200)
cast = models.CharField(max_length = 200)
description = models.TextField(default="")
image = models.ImageField(upload_to = 'movies_pics')
def __str__(self):
return self.title```
And a model Listed -
```class Listed(models.Model):
Choices = ((1,'1'),(2,'2'),(3,'3'),(4,'4'),(5,'5'),(6,'6'),(7,'7'),(8,'8'),(9,'9'),(10,'10'))
user = models.ForeignKey(User, on_delete=models.CASCADE, default = "")
movie = models.OneToOneField(Movie, on_delete=models.CASCADE)
review = models.TextField(default="")
rating = models.IntegerField(choices = Choices)
def __str__(self):
return f'{self.movie.title} Listed'```
I have made it so that a user can add a movie onto his list and then add a review and rating and create a Listed Model. I have a CreateView to make a new Listed model -
```class MovieAddView(CreateView):
model = Listed
fields = ['review','rating']
template_name = 'movie/movie_add.html'
def form_valid(self, form):
self.object = form.save()
return HttpResponseRedirect(reverse('user-movies'))```
The problem is that whenever a new Listed Model is made I need a way to pass in the current Movie model as well for the OneToOneField. Otherwise it raises an error of - "NOT NULL constraint failed movie_listed.movie_id", because there is no Movie model being passed in. Can anyone help? Do I need to use a signal?