Settings Reference¶
Django Settings¶
All settings are optional and have sensible defaults. Configure them in your Django settings module:
# settings.py
DISPLAY_IDS = {
"UUID_FIELD": "id",
"SLUG_FIELD": "slug",
"STRATEGIES": ("display_id", "uuid", "slug"),
"SLUG_REGEX": r"[-a-zA-Z0-9_]+",
}
Available Settings¶
Setting |
Default |
Description |
|---|---|---|
|
|
Default UUID field name for lookups |
|
|
Default slug field name for lookups |
|
|
Default lookup strategies (in order) |
|
|
Regex pattern for slug matching in URL converters |
SLUG_REGEX¶
The SLUG_REGEX setting controls what patterns are considered valid slugs
in the DisplayIDOrSlugConverter and
DisplayIDOrUUIDOrSlugConverter.
By default, it uses Django’s slug pattern ([-a-zA-Z0-9_]+), which allows:
Letters (uppercase and lowercase)
Numbers
Hyphens
Underscores
To restrict to lowercase slugs only:
DISPLAY_IDS = {
"SLUG_REGEX": r"[a-z0-9-]+",
}
To allow dots in slugs:
DISPLAY_IDS = {
"SLUG_REGEX": r"[-a-zA-Z0-9_.]+",
}
View/Mixin Attributes¶
All mixins accept these attributes to override defaults:
Attribute |
Default |
Description |
|---|---|---|
|
|
URL parameter name to read |
|
from settings |
Tuple of strategies to try |
|
from model |
Expected display ID prefix |
|
|
UUID field name on model |
|
|
Slug field name on model |
Model Class Attributes¶
Models using DisplayIDModel can define:
Attribute |
Required |
Description |
|---|---|---|
|
Yes |
Prefix for display IDs (1-16 lowercase letters) |
|
No |
Override default UUID field name |
|
No |
Override default slug field name |
Attribute Precedence¶
When resolving configuration, attributes are checked in this order:
View/mixin attribute (e.g.,
self.display_id_prefix)Model class attribute (e.g.,
Model.display_id_prefix)Django settings (
DISPLAY_IDS["..."])Built-in default
This allows you to set project-wide defaults in settings while overriding specific views or models as needed.