5

is there any way to integrate an autoslugfield from django-autoslug into the Django-admin interface? I tried putting it inside a list_display as 'slug' but it doesn't show up then in the django-admin interface.

Thanks a lot

jhagege
  • 1,486
  • 3
  • 22
  • 36

2 Answers2

4

This is old question but maybe someone will find this answer usefull to display in admin interface (and make it editable)

all you need to do set editable=True

slug = AutoSlugField(populate_from='title', editable=True, blank=True)

and now its autogenerated only if slug is not filled... and also slug is not regenerated in pupulated_from is changed.

Linum
  • 311
  • 1
  • 8
2

Why do you want to add it into admin interface? It shouldn't be editable anyway.

You can add it as a read-only field though.

class MyModelAdmin(admin.ModelAdmin):
   list_display = ('slug',)
   readonly_fields = ('slug',)
Artur Barseghyan
  • 12,746
  • 4
  • 52
  • 44
  • Why should it be editable? Because if you change the name/title field, you want the slug updated to match. We can assume the site admin knows this will break incoming links to any URL that uses the slugfield, but better to give the admin that power than to take it away. – shacker Oct 25 '18 at 06:12
  • @shacker: If you want to have control, you shouldn't use `auto-slug`. However, there are many easy ways around it. Easiest I could think of is to define another non-managed model which would contain the slug only and in that case it shouldn't be auto-slug field, but simple Django `SlugField`. – Artur Barseghyan Oct 26 '18 at 20:36