10.4.2 Adding a slug to NewsLink

Adding a SlugField to NewsLink is really easy, given Django’s declarative syntax, as shown in Example 10.21.

Example 10.21: Project Code

organizer/models.py in 89c25fd8a8

70  class NewsLink(models.Model):  .      ... 72      slug = models.SlugField(max_length=63)

That’s it! You’re done. (Take heed: we have not set the unique option on the field.)

Mirroring this change in the database and making the lives of your future self and your coworkers easy is a little trickier, especially because we have a database with data in it.

When we call makemigrations, Django compares the current state of our models with the historical models it builds thanks to the Apps and AppConfig classes. It ...

Get Django Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.