18.8.1 NewsLink URL patterns
At the moment, our website uses the primary keys of NewsLink objects in the URL patterns of related views. This practice is frowned upon, and we want to switch to using the SlugField of the NewsLink object, a field we added in Chapter 10: Revisiting Migrations.
The trick to our new URL patterns is that the slug does not uniquely identify the NewsLink object. Instead, the combination of startup and slug does. Our URL patterns thus need to use two slugs to identify the NewsLink. That’s somewhat tricky. All of our pages simply use slug as a variable name in regular expression patterns, and now we have to differentiate between startup_slug and newslink_slug in some instances.
As these views will now be associated with ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access