[Answered ]-Can any one tell how can i get an appropriate output only using a foreign key in models

1👍

First I would use a ManyToMany relationship between the movies and the actors.
This would look something like this:

models.py:

class Actorlist(models.Model):
    Name = models.CharField(max_length=1000)
    DateofBirth = models.DateTimeField(verbose_name='Date of Birth',blank=True)

    def __str__(self):
        return self.Name


class Movielist(models.Model) :
    Title = models.CharField(max_length=1000)
    Description = models.TextField(blank=True)
    ReleaseDate = models.DateTimeField(verbose_name='Release Date', blank=True)
    Upvote = models.IntegerField(default=0)
    Downvote = models.IntegerField(default=0)
    Actors = models.ManyToManyField(Actorlist)
    
    def __str__(self):
        return self.Title


After that you should see the actors in your output.
I would also recommend reading the relationship documentation from django-rest-framework:

https://www.django-rest-framework.org/api-guide/relations/

Leave a comment