Reputation: 2032
Since Django does not accept Foreign Keys as a slug, I currently do not have slugs setup on my model, however, I do have the slug field in the model. To get my slugs quickly, I created a page listing all the issues and used {{ issue|slugify }}
and have them sorted by ID (which is the same ID in my PostgreSQL tables). In PostgreSQL, I can sort the issue tables by ID as well.
So my question is how do I insert the news slugs into the database? ** I am not familiar with PostgreSQL so baby talk would be nice.
Upvotes: 0
Views: 252
Reputation: 5206
If you're just looking to update the value of your slug field for all your existing models you should be able to do it like this:
from django.db import F
from django.template.defaultfilters import slugify
YourModel.objects.all().update(your_slug_field=slugify(F('the_field_youre_slugging')))
I haven't tested this though.
However, it also doesn't address how you are going to set this slug field when you create your records. There are multiple ways to do this: override the save() method, a callable as default, as well as numerous others with various advantages and disadvantages.
Upvotes: 1