Skip to content

Instantly share code, notes, and snippets.

@aliceridgway
Created June 11, 2022 15:19
Show Gist options
  • Save aliceridgway/fca1b492a23292bb8229c275862f9167 to your computer and use it in GitHub Desktop.
Save aliceridgway/fca1b492a23292bb8229c275862f9167 to your computer and use it in GitHub Desktop.
Movie Model
from django.db import models
from autoslug import AutoSlugField
from django.urls import reverse
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
)
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", blank=True
)
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse("movie_detail", kwargs={"slug": self.slug})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment