Skip to content

Commit

Permalink
black reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
KommuSoft committed Sep 17, 2023
1 parent 9dee0c2 commit c7a170f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions django_enforced_choices/fields/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class ChoicesConstraintMixin:
This check can be disabled by passing check_choices=False. We can omit enforcing choices
by passing ensure_choices=False.
"""

def __init__(self, *args, check_choices=True, ensure_choices=True, **kwargs):
super().__init__(*args, **kwargs)
self.ensure_choices = ensure_choices
Expand Down
4 changes: 3 additions & 1 deletion django_enforced_choices/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ class ChoicesConstraintModelMetaMixin(ModelBase):
A meta-class with the logic in the _prepare method to inspect the fields, and
add CheckConstraints for the fields that have choices.
"""

def _prepare(cls, *args, **kwargs):
"""
Override the _prepare method to also add CheckConstraints for the corresponding
fields.
"""
to_exclude = getattr(cls, 'exclude_choice_check_fields', ()) or ()
to_exclude = getattr(cls, "exclude_choice_check_fields", ()) or ()
super()._prepare(*args, **kwargs)
for field in cls._meta.fields:
if field.name not in to_exclude:
Expand All @@ -29,4 +30,5 @@ class ChoicesConstraintModelMixin(metaclass=ChoicesConstraintModelMetaMixin):
from the ChoicesConstraintsModelMetaMixin, a subclass of ModelBase, which
has some extra _prepare logic.
"""

exclude_choice_check_fields = ()

0 comments on commit c7a170f

Please sign in to comment.