python - django model.delete() raises ValueError - needs to have a value for field before this many-to-many relationship can be used -



python - django model.delete() raises ValueError - needs to have a value for field before this many-to-many relationship can be used -

i have overritten save_model() method in django modeladmin class. model has manytomany field. save_model looks this:

def save_model(self, request, obj, form, change): creating = false to_delete = false if not obj.pk: creating = true obj.save() form.save_m2m() # observe (some complicated conditions) here ... detected =true if detected: obj.delete() # --> here problem traceback: file "/library/python/2.7/site-packages/django/core/handlers/base.py" in get_response 111. response = callback(request, *callback_args, **callback_kwargs) file "/library/python/2.7/site-packages/django/contrib/admin/options.py" in wrapper 366. homecoming self.admin_site.admin_view(view)(*args, **kwargs) file "/library/python/2.7/site-packages/django/utils/decorators.py" in _wrapped_view 91. response = view_func(request, *args, **kwargs) file "/library/python/2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func 89. response = view_func(request, *args, **kwargs) file "/library/python/2.7/site-packages/django/contrib/admin/sites.py" in inner 196. homecoming view(request, *args, **kwargs) file "/library/python/2.7/site-packages/django/utils/decorators.py" in _wrapper 25. homecoming bound_func(*args, **kwargs) file "/library/python/2.7/site-packages/django/utils/decorators.py" in _wrapped_view 91. response = view_func(request, *args, **kwargs) file "/library/python/2.7/site-packages/django/utils/decorators.py" in bound_func 21. homecoming func(self, *args2, **kwargs2) file "/library/python/2.7/site-packages/django/db/transaction.py" in inner 209. homecoming func(*args, **kwargs) file "/library/python/2.7/site-packages/django/contrib/admin/options.py" in add_view 956. self.save_related(request, form, formsets, false) file "/library/python/2.7/site-packages/django/contrib/admin/options.py" in save_related 731. form.save_m2m() file "/library/python/2.7/site-packages/django/forms/models.py" in save_m2m 83. f.save_form_data(instance, cleaned_data[f.name]) file "/library/python/2.7/site-packages/django/db/models/fields/related.py" in save_form_data 1273. setattr(instance, self.attname, data) file "/library/python/2.7/site-packages/django/db/models/fields/related.py" in __set__ 859. manager = self.__get__(instance) file "/library/python/2.7/site-packages/django/db/models/fields/related.py" in __get__ 846. through=self.field.rel.through, file "/library/python/2.7/site-packages/django/db/models/fields/related.py" in __init__ 538. (instance, source_field_name)) exception type: valueerror @ /admin/lawis_core/invoice/add/ exception value: "<invoice: 1301000>" needs have value field "invoice" before many-to-many relationship can used.

could forgot phone call super class? this:

class youradmin(admin.modeladmin) def save_model(self, request, obj, form, change): super(youradmin, self).save_model(request, obj, form, change) # code ...

python django

Comments

Popular posts from this blog

javascript - mongodb won't find my schema method in nested container -

How do you set up a perforce server to work over the internet? -

ios - Lagging ScrollView with UIWebview inside -