Skip to content

Instantly share code, notes, and snippets.

@aliceridgway
Created June 5, 2022 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aliceridgway/18d709ca2464ea4797cf6c9494a6e7e2 to your computer and use it in GitHub Desktop.
Save aliceridgway/18d709ca2464ea4797cf6c9494a6e7e2 to your computer and use it in GitHub Desktop.
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