Changeset View
Changeset View
Standalone View
Standalone View
blog/models.py
| from typing import Optional, Union, Sequence | from typing import Optional, Union, Sequence | ||||
| from django.contrib.auth.models import User | from django.contrib.auth.models import User | ||||
| from django.db import models | from django.db import models | ||||
| from django.urls import reverse | from django.urls import reverse | ||||
| from comments.models import Comment | from comments.models import Comment | ||||
| from common import mixins, markdown | from common import mixins, markdown | ||||
| from common.upload_paths import get_upload_to_hashed_path | from common.upload_paths import get_upload_to_hashed_path | ||||
| from films.models import Film | from films.models import Film | ||||
| from static_assets.models import StorageLocation | |||||
| class Post(mixins.CreatedUpdatedMixin, models.Model): | class Post(mixins.CreatedUpdatedMixin, models.Model): | ||||
| film = models.ForeignKey( | film = models.ForeignKey( | ||||
| Film, blank=True, null=True, on_delete=models.CASCADE, related_name='posts' | Film, blank=True, null=True, on_delete=models.CASCADE, related_name='posts' | ||||
| ) | ) | ||||
| # TODO(sem): Maybe add a ForeignKey to a Profile instead? Because authors | # TODO(sem): Maybe add a ForeignKey to a Profile instead? Because authors | ||||
| # might not have an account per se. | # might not have an account per se. | ||||
| Show All 31 Lines | class Revision(mixins.CreatedUpdatedMixin, models.Model): | ||||
| editor = models.ForeignKey(User, on_delete=models.PROTECT, related_name='edited_posts') | editor = models.ForeignKey(User, on_delete=models.PROTECT, related_name='edited_posts') | ||||
| title = models.CharField(max_length=512) | title = models.CharField(max_length=512) | ||||
| topic = models.CharField(max_length=128) | topic = models.CharField(max_length=128) | ||||
| description = models.TextField( | description = models.TextField( | ||||
| blank=True, help_text='An optional short description displayed on the blog card.' | blank=True, help_text='An optional short description displayed on the blog card.' | ||||
| ) | ) | ||||
| content = models.TextField() | content = models.TextField() | ||||
| html_content = models.TextField(blank=True, editable=False) | html_content = models.TextField(blank=True, editable=False) | ||||
| storage_location = models.ForeignKey( | |||||
| StorageLocation, on_delete=models.PROTECT, related_name='revisions' | |||||
| ) | |||||
| thumbnail = models.FileField(upload_to=get_upload_to_hashed_path) | thumbnail = models.FileField(upload_to=get_upload_to_hashed_path) | ||||
| is_published = models.BooleanField(default=False) | is_published = models.BooleanField(default=False) | ||||
| def save( | def save( | ||||
| self, | self, | ||||
| force_insert: bool = False, | force_insert: bool = False, | ||||
| force_update: bool = False, | force_update: bool = False, | ||||
| Show All 31 Lines | |||||