emencia / django-blog-lotus

A weblog application with Django.
https://django-blog-lotus.readthedocs.io/
MIT License
5 stars 1 forks source link

Article constraint at db or programming level #8

Closed sveetch closed 3 years ago

sveetch commented 3 years ago

Currently An Article can't have the same combination of slug, publish date and language, this is enforced at db level with a model constraint. This has been made because we plan to have Article detail url on this combination so user can create many Article with either the same slug or same date.

But if a developer want to change urls to display only the slug and not the date, the slug should be unique.

It could be possible to manage constraint in some validators which could be customized, but it may decrease performance against the db level way.. ?

sveetch commented 3 years ago

Also i thought of a case with the publish start which is a datetime. But urls will only use the date part, not the time. This is buggy since two articles with the same slug can have the same date but a different time but this will result to an error when trying to resolve their object from url arguments.

Django did this at programming level: https://docs.djangoproject.com/en/3.1/ref/models/fields/#unique-for-date

sveetch commented 3 years ago

I don't have many idea for correct implementation of custom constraint management and not enough time to think about it. Also the db level implementation is still a nice way to do it so we will keep it.

Finally, i just refactored modelization so we use a simple date for publication start to avoid problem with unique constraint on date+lang+slug.