Django: is it better to save the pool in the database or generate dynamically if they are used for searching?

So this is almost a duplicate of this question , except that I do want to use slug for the search.

My urls are as follows:

http://url.com/county/place-name

The unique combination of "county" and "place-name" is used to search for the database object, except that the "place-name" is stored in the database as "Place Name".

Therefore, if I do not store the place name in the database as a separate slip field, I need to delete it first and then do a search.

Is Django safe or waste disposal possible? Or is it better for me to add the slame-name slug field to the database and populate it whenever a new object is added?

+3
source share
1 answer

I would always save it in the database if it was used for searching: you should avoid broken URLs, just in case you need to change the domain name. If you later need to change the slugification algorithm for any reason, at least the old data will not break. Etc.

If you need to change slugs later, you can at least cope with migration while maintaining old slips.

+4
source

Source: https://habr.com/ru/post/1759809/


All Articles