How would you fill in a field based on another field

In the admin panel, I want to populate the slug field based on a specific text field

eg.

Title: My Awesome Page

will be automatically filled

Slug: my_awesome_page

+3
source share
2 answers

For SlugField, the prepoulate_from option to 0.96 was used before. After that, he became administrative. See here for reference.

Alternatively, you can override the model save method to calculate the value of the slug field in the save () file.

This question may also be helpful.

+5
source

, django-autoslug, AutoSlugField. , :

class Something(models.Model):
    title = models.CharField(max_lenght=200)
    slug = AutoSlugField(populate_from='title')
    ...

AutoSlugField , , - (, DateTimeField).

. http://pypi.python.org/pypi/django-autoslug.

+1

Source: https://habr.com/ru/post/1702900/


All Articles