March 2020
Intermediate to advanced
608 pages
17h 17m
English
Open the models.py file of any Django app that you want to use mixins with, and type the following code:
# myproject/apps/ideas/models.pyfrom django.db import modelsfrom django.urls import reversefrom django.utils.translation import gettext_lazy as _from myproject.apps.core.models import ( CreationModificationDateBase, MetaTagsBase, UrlBase,)class Idea(CreationModificationDateBase, MetaTagsBase, UrlBase): title = models.CharField( _("Title"), max_length=200, ) content = models.TextField( _("Content"), ) # other fields… class Meta: verbose_name = _("Idea") verbose_name_plural = _("Ideas") def __str__(self): return self.title def get_url_path(self): return reverse("idea_details", kwargs={ "idea_id": str(self.pk), })
Read now
Unlock full access