AttributeError overriding save_existing_objects in Formset class

74 views
Skip to first unread message

Vincenzo

unread,
Aug 9, 2016, 12:56:17 PM8/9/16
to Django users
Hi there,
I'm using the admin and I have a form admin  and an inline admin form. For this inline admin, I need to ignore modifications done for existing items: for this task I have done an override of save_existing_objects method for a Formset which inherit from forms.models.BaseInlineFormset. In this function I simply call the super with commit=False but doing that cause the following error:

traceback (most recent call last):
 
File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-packages/django/core/handlers/base.py", line 149, in get_response
    response
= self.process_exception_by_middleware(e, request)
 
File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-packages/django/core/handlers/base.py", line 147, in get_response
    response
= wrapped_callback(request, *callback_args, **callback_kwargs)
 
File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-packages/django/contrib/admin/options.py", line 541, in wrapper
   
return self.admin_site.admin_view(view)(*args, **kwargs)
 
File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-packages/django/utils/decorators.py", line 149, in _wrapped_view
    response
= view_func(request, *args, **kwargs)
 
File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-packages/django/views/decorators/cache.py", line 57, in _wrapped_view_func
    response
= view_func(request, *args, **kwargs)
 
File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-packages/django/contrib/admin/sites.py", line 244, in inner
   
return view(request, *args, **kwargs)
 
File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-packages/reversion/admin.py", line 186, in change_view
   
return super(VersionAdmin, self).change_view(request, object_id, form_url, extra_context)
 
File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-packages/django/contrib/admin/options.py", line 1440, in change_view
   
return self.changeform_view(request, object_id, form_url, extra_context)
 
File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-packages/django/utils/decorators.py", line 67, in _wrapper
   
return bound_func(*args, **kwargs)
 
File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-packages/django/utils/decorators.py", line 149, in _wrapped_view
    response
= view_func(request, *args, **kwargs)
 
File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-packages/django/utils/decorators.py", line 63, in bound_func
   
return func.__get__(self, type(self))(*args2, **kwargs2)
 
File "/usr/lib/python3.4/contextlib.py", line 30, in inner
   
return func(*args, **kwds)
 
File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-packages/django/contrib/admin/options.py", line 1379, in changeform_view
   
self.save_related(request, form, formsets, not add)
 
File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-packages/django/contrib/admin/options.py", line 1015, in save_related
   
self.save_formset(request, form, formset, change=change)
 
File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-packages/django/contrib/admin/options.py", line 1003, in save_formset
    formset
.save()
 
File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-packages/django/forms/models.py", line 645, in save
   
return self.save_existing_objects(commit) + self.save_new_objects(commit)
 
File "/home/vincenzo/workspace/mynetgest2/warehouse/forms.py", line 118, in save_existing_objects
    instances_not_saved
= super(IncomingBillOfLadingRowFormset, self).save_existing_objects(commit=False)
 
File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-packages/django/forms/models.py", line 763, in save_existing_objects
   
self.saved_forms.append(form)
AttributeError: 'IncomingBillOfLadingRowFormFormSet' object has no attribute 'saved_forms'

Is there something I'm doing wrong?

Constantine Covtushenko

unread,
Aug 9, 2016, 4:04:57 PM8/9/16
to django...@googlegroups.com
Hi Vincenzo,

Can you please specify Django version that you are using.

Regards,

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/cc82fa71-3edb-49f7-b46b-c1f043eafd2a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vincenzo

unread,
Aug 10, 2016, 3:14:46 AM8/10/16
to Django users, constantine...@gmail.com
The Django version I'm using is the 1.9.4
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

Constantine Covtushenko

unread,
Aug 10, 2016, 3:11:37 PM8/10/16
to django...@googlegroups.com
I believe that you should also override `save` method with your commit=False.

That `save` method and `save_existing_objects` method works in sync. It is supposed that they should have the same `commit` value.

Hope that helps,

To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages