You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Just updated to 2.1 and when I try to submit formcollections with dialogmodelforms I've got an errors AttributeError: 'AddDishCatalogForm' object has no attribute 'cleaned_data'. Did you mean: 'changed_data'?
It happens in def construct_instance(self, instance=None): of collection.py. It happens because DialogModelFroms trying to get to construct_instance. I fix it with condition if not hasattr(holder, 'cleaned_data'): continue:
def construct_instance(self, instance=None):
"""
Construct the main instance and all its related objects from the nested dictionary. This
method may only be called after the current form collection has been validated, usually by
calling `is_valid`.
Forms and Collections which do not correspond to the model given by the starting instance,
are responsible themselves to override this method in order to store the corresponding data
inside their related models.
"""
assert self.is_valid(), f"Can not construct instance with invalid collection {self.__class__} object"
if self.has_many:
for valid_holders in self.valid_holders:
# first, handle holders which are forms
for name, holder in valid_holders.items():
if not isinstance(holder, BaseModelForm):
continue
if holder.marked_for_removal:
holder.instance.delete()
continue
construct_instance(holder, holder.instance)
if getattr(self, 'related_field', None):
setattr(holder.instance, self.related_field, instance)
try:
holder.save()
except (IntegrityError, ValueError) as error:
# some errors are caught only after attempting to save
holder._update_errors(error)
# next, handle holders which are sub-collections
for name, holder in valid_holders.items():
if callable(getattr(holder, 'construct_instance', None)):
holder.construct_instance(holder.instance)
else:
for name, holder in self.valid_holders.items():
if callable(getattr(holder, 'construct_instance', None)):
holder.construct_instance(instance)
elif isinstance(holder, BaseModelForm):
// This is my condition
if not hasattr(holder, 'cleaned_data'):
continue
//
opts = holder._meta
holder.cleaned_data = self.cleaned_data[name]
holder.instance = instance
construct_instance(holder, instance, opts.fields, opts.exclude)
try:
holder.save()
except IntegrityError as error:
holder._update_errors(error)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Just updated to 2.1 and when I try to submit formcollections with dialogmodelforms I've got an errors AttributeError: 'AddDishCatalogForm' object has no attribute 'cleaned_data'. Did you mean: 'changed_data'?
It happens in def construct_instance(self, instance=None): of collection.py. It happens because DialogModelFroms trying to get to construct_instance. I fix it with condition if not hasattr(holder, 'cleaned_data'): continue:
Is it correct?
Beta Was this translation helpful? Give feedback.
All reactions