-
Book Overview & Buying
-
Table Of Contents
Web Development with Django Cookbook - Second Edition
By :
For every model that has its own page, it is good practice to define the get_absolute_url() method. This method can be used in templates and also in the Django admin site to preview the saved object. However, get_absolute_url() is ambiguous as it returns the URL path instead of the full URL. In this recipe, we will see how to create a model mixin that allows you to define either the URL path or the full URL by default, generate the other out of the box, and take care of the get_absolute_url() method that is being set.
If you haven't done it yet, create the utils package to save your mixins. Then, create the models.py file in the utils package (alternatively, if you create a reusable app, put the mixins in the base.py file in your app).
Execute the following steps one by one:
Add the following content to the models.py file of your utils package:
# utils/models.py
# -*- coding: UTF-8 -*-
from __future__ import unicode_literals...
Change the font size
Change margin width
Change background colour