no_freedom no_freedom - 5 months ago 59
Python Question

Generate slug field in existing table

I have table with data. Is it possible slug field automatically generated on existing table? Or is there any other alternative? Thanks
Here is my table

enter image description here


Using the slugify template filter, you can write a script, or loop through the objects in the shell.

>>> from django.template.defaultfilters import slugify
>>> for obj in MyModel.objects.all():
...     obj.slug = slugify(obj.title)