Add corpus categories
https://redmine.teklia.com/issues/11416
A new arkindex.documents.models.CorpusCategory model should be added, with the following fields:
-
id, anAutoFieldas the primary key; -
created, aDateTimeFieldwithauto_now_addset; -
updated, aDateTimeFieldwithauto_nowset; -
slug, aSlugFieldwithdb_index=Falseto disable the implicit and unnecessary database index that Django creates, and with aMinLengthValidatorto ensure you can't use an empty slug; -
display_name, aCharFieldwith aMinLengthValidator; -
color, aCharFieldwith a regex validator to ensure it is always a 6 character hex code, just like inEntityType.colorandElementType.color, and ahelp_textto explain to instance administrators that this is a 6 character code (it will be shown automatically in the Django admin).
Two UniqueConstraint should be declared on this model to require unique values for both slugs and display names. Do not use unique=True on the fields themselves, as explained in the best practices.
A CorpusCategory.__str__ method should return the display_name.
A new Corpus.category foreign key assigns one CorpusCategory to each corpus. It is nullable for now.
The database migration should:
- Create
CorpusCategory - Create
Corpus.category - In a
RunPythonoperation:- Create a default
CorpusCategorywith the slug set todefault, the display name toDefaultand the color toFF0000 - In a single
update()call, assign this category to all existing corpora.
- Create a default
CorpusCategory should be added to the Django admin. The list shows slugs and display names, and orders by slug by default. Creating a CorpusCategory with a slug or a display name that already exist should result in a clean error message, not a crash.
Corpus.category should be editable in the Django admin. The corpora list must include the category column, which should show the category's display_name. Make sure there isn't one query per corpus to retrieve the category, which would make the admin page very slow; you might need to add a select_related manually to handle this. When creating or updating a single corpus, it should be possible to set a category.