fromdjango.dbimportmodelsfromdjango.utils.translationimportgettext_lazyas_SINGLETON_ERROR=_("Model {model_name} has already one instance")
[docs]classSingletonManager(models.Manager):""" A manager to ensure that only one instance of the model exists. This manager overrides the `create` method to enforce a singleton pattern on the associated model. If an instance of the model already exists, attempting to create another instance will raise a `ValueError`. Methods: create(**kwargs): Creates a new instance of the model if none exists. Raises `ValueError` if an instance already exists. """