Skip to content

Commit

Permalink
Merge adc2798 into 1ad9563
Browse files Browse the repository at this point in the history
  • Loading branch information
matllubos committed Oct 14, 2018
2 parents 1ad9563 + adc2798 commit 8ed5494
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion chamber/models/__init__.py
Expand Up @@ -323,7 +323,7 @@ def _save(self, is_cleaned_pre_save=None, is_cleaned_post_save=None, force_inser

origin = self.__class__

change = bool(self.pk)
change = not self._state.adding
kwargs.update(self._get_save_extra_kwargs())

self._call_pre_save(change, self.changed_fields, *args, **kwargs)
Expand Down
6 changes: 4 additions & 2 deletions chamber/models/fields.py
Expand Up @@ -212,9 +212,11 @@ def __init__(self, *args, **kwargs):
def validate(self, value, model_instance):
super(EnumSequenceFieldMixin, self).validate(value, model_instance)
if self.enum:
prev_value = model_instance.pk and model_instance.initial_values[self.attname] or None
prev_value = (not model_instance._state.adding and model_instance.initial_values[self.attname]) or None
allowed_next_values = self.enum.get_allowed_next_states(prev_value, model_instance)
if self.name in model_instance.changed_fields and value not in allowed_next_values:

if ((self.name in model_instance.changed_fields or model_instance._state.adding) and
value not in allowed_next_values):
raise ValidationError(
ugettext('Allowed choices are {}.').format(
', '.join(('{} ({})'.format(*(self.enum.get_label(val), val)) for val in allowed_next_values))))
Expand Down

0 comments on commit 8ed5494

Please sign in to comment.