no_freedom no_freedom - 1 year ago 138
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

Answer Source

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)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download