Make auto populated slug field in Django admin


Django admin have great feature called “prepopulated”. Here is an example to create auto populated slug in Django admin without using any additional Jquery scripts.

1
2
3
4
5
6
7
8
9
10
11
from django.contrib import admin
from photos.forms import PhotoAdminForm
from photos.models import Photo

class PhotoAdmin(admin.ModelAdmin):
    list_display = (‘title’, ‘admin_image’)
    prepopulated_fields = {‘slug’:(‘title’,)}

    form = PhotoAdminForm

admin.site.register(Photo, PhotoAdmin)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.