get_absolute_url
One more thing that we are seeing for the first time in the Car
model is get_absolute_url
. There is nothing special about the implementation. It's just a class method that returns a URL, which it builds using the reverse
function and the primary key of the object. This isn't anything new. We have been creating URLs like this for detail pages since the first chapter. What's interesting to note here is that Django assigns special meaning to the get_absolute_url
method on a model class. There are a number of places where Django will automatically use the return value of the get_absolute_url
method if the method exists on a model object. For instance, the CreateView
generic method uses it. If you do not provide a success_url
attribute ...
Get Django Project Blueprints now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.