Changeset View
Changeset View
Standalone View
Standalone View
films/models/flatpages.py
- This file was added.
| from django.contrib.flatpages.models import FlatPage | |||||
| from django.db import models | |||||
| from common import mixins, markdown | |||||
| from films.models import Film | |||||
| class ExtendedFlatPage(mixins.CreatedUpdatedMixin, FlatPage): | |||||
| html_content = models.TextField(blank=True, editable=False) | |||||
sybren: The name doesn't convey anything about the purpose of this class, beyond the fact that it has a… | |||||
| film = models.ForeignKey(Film, on_delete=models.CASCADE, related_name='flatpages') | |||||
| def clean(self) -> None: | |||||
| super().clean() | |||||
| self.html_content = markdown.render(self.content) | |||||
sybrenUnsubmitted Not Done Inline ActionsDoing this in clean() means that this code doesn't run when you call flatpage.save() (docs). Is that intentional? sybren: Doing this in `clean()` means that this code doesn't run when you call `flatpage.save()`… | |||||
natkaAuthorUnsubmitted Done Inline ActionsHm, the docs also say that clean is a good place to automatically provide a value for a field, and we've done it this way in other models. Certainly there's no particular intention to avoid running this code on flatpage.save() - we just don't manually call save() anywhere, so I did not assume that it was a problem. Do you think it would make more sense to put this code in save() in this case? natka: Hm, the docs also say that clean is a good place to automatically provide a value for a field… | |||||
The name doesn't convey anything about the purpose of this class, beyond the fact that it has a few extra properties.
Currently there are multiple things happening in this class:
This looks like it could be split up in two classes, one for each 'thing'. I think that the content type change to MarkDown could be moved into a mix-in class and placed in the common.models module.