O'Reilly logo

Django Unleashed by Andrew Pinkham

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required