November 2015
Beginner to intermediate
840 pages
26h 30m
English
get_absolute_url()The ultimate way to adhere to DRY while generating links is to provide a get_absolute_url() method to each model class, allowing for the quick retrieval of each model object’s canonical URL path.
get_absolute_url in TagLet’s focus on our Tag model class first. To reverse a URL in Python, we need the reverse() method, and so we start by importing it in Example 6.33.
Example 6.33: Project Code
organizer/models.py in dbcee003de
1 from django.core.urlresolvers import reverse
We can then focus on creating the method. The organizer_tag_detail URL pattern reads as in Example 6.34.
Example 6.34: Project Code
Read now
Unlock full access