What would be the generic way to create record title and slub based on the ID? I am working with django-photologue here. I want to save a record with title and slug based on the PK. The generic problem is that I can't get the PK until the record is saved into database. On the other side, I can't save it without title and slug.
What common solution is that that kind of problem?
If you URIs are supposed to look like "example.com/${obj.id}-${sluggify( obj.title )}"
then generate these uri when you use them. This uri contains no data that's not in the DB already, so don't add it again. The slug's sole purpose is making url's look nicer to people and search engines.
Take Stackoverflow as an example: Creating Title / Slug based on PK ID
If you want to select by the slug only, it has to be a Primary Key, unique and immutable. You should be aware that having another PK, the usual id
column, would be unneeded.
I don't say slugs are bad, nor that saving slugs is always bad. There are many valid reasons to save them in the database, but then you need to think about what you're doing.
Selecting data by their PK (and ignoring the slug) on the other hand requires no thinking, so that should be the default way to go.