'Matching API data with sql data

New to Python and APIs

I am trying to connect the TMDB api data to the data I have in my db.

To be more specific, I have access to specific poster_paths and other data when entering a specific [550?] id into the url endpoint and print it on the DOM but I can't figure out how to dynamically match the poster_path with my Show model class, such as title.

Here is the def functionality so far: def index(request):

post =  Show.objects.all().order_by('id')

#api 

api_key = ""
base_url = "https://api.themoviedb.org/3"
api_url = base_url + "/tv/500?" + api_key

        # json data
resp = requests.get(api_url)
data = resp.json()
        
        #created by
name = data['created_by'][0]['name']

        # poster path
poster_path = data['poster_path']
img_url = "https://image.tmdb.org/t/p/w500"+ poster_path

And here is my models class :

class Show(models.Model):
    title = models.CharField(max_length=200)
    #description = models.TextField()
    count = models.IntegerField()
    #year = models.IntegerField()
    script = models.FileField(blank=True, null=True, upload_to="screenplays")
    #poster = models.ImageField(blank=True, null=True, default='default.jpg', upload_to="posters")
    creators = models.ManyToManyField(Creator, related_name='shows')
    tag = models.ManyToManyField(Tag)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True) ```



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source