11from django .conf import settings
22from django .utils .text import slugify
3+ from django .core .exceptions import ImproperlyConfigured
34
5+ from ..util import get_language_codes
6+ from ..mixins import AtomicSlugRetryMixin
47from ..localized_value import LocalizedValue
58from .localized_autoslug_field import LocalizedAutoSlugField
6- from ..util import get_language_codes
79
810
911class LocalizedUniqueSlugField (LocalizedAutoSlugField ):
@@ -17,6 +19,8 @@ class LocalizedUniqueSlugField(LocalizedAutoSlugField):
1719 - Improved performance
1820
1921 When in doubt, use this over :see:LocalizedAutoSlugField.
22+ Inherit from :see:AtomicSlugRetryMixin in your model to
23+ make this field work properly.
2024 """
2125
2226 def __init__ (self , * args , ** kwargs ):
@@ -46,6 +50,12 @@ def pre_save(self, instance, add: bool):
4650 The localized slug that was generated.
4751 """
4852
53+ if not isinstance (instance , AtomicSlugRetryMixin ):
54+ raise ImproperlyConfigured ((
55+ 'Model \' %s\' does not inherit from AtomicSlugRetryMixin. '
56+ 'Without this, the LocalizedUniqueSlugField will not work.'
57+ ) % type (instance ).__name__ )
58+
4959 slugs = LocalizedValue ()
5060
5161 for lang_code , _ in settings .LANGUAGES :
0 commit comments