Created
June 5, 2022 12:26
-
-
Save aliceridgway/18d709ca2464ea4797cf6c9494a6e7e2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from autoslug import AutoSlugField | |
from django.utils.text import slugify | |
class Genre(models.Model): | |
name = models.CharField(max_length=100) | |
api_id = models.IntegerField(unique=True) | |
def __str__(self): | |
return self.name | |
class Movie(models.Model): | |
api_id = models.IntegerField(unique=True) | |
title = models.CharField(max_length=255) | |
slug = AutoSlugField( | |
populate_from='title', | |
editable=True, | |
always_update=True, | |
unique=True | |
) | |
slug2 = models.SlugField(max_length=255) | |
overview = models.TextField(blank=True, null=True) | |
popularity = models.FloatField(blank=True, null=True) | |
poster_path = models.CharField(max_length=255, blank=True, null=True) | |
backdrop_path = models.CharField(max_length=255, blank=True, null=True) | |
release_date = models.DateField() | |
added = models.DateTimeField(auto_now_add=True) | |
active = models.BooleanField(default=False) | |
deleted = models.BooleanField(default=False) | |
genres = models.ManyToManyField(to=Genre, related_name="movies") | |
def save(self, **kwargs): | |
self.slug2 = slugify(self.title) | |
super(Movie, self).save(**kwargs) | |
def __str__(self): | |
return self.title |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment