python - Django custom save decorator causing Internal Error in formset saving (inline in admin) -
i have custom save method , custom decorator run django's model save() before , after custom save:
models.py:
from django.contrib.auth.models import user django.db import models def save_decorator(method_to_decorate): def wrapper(self, *args, **kwargs): super(type(self), self).save(*args, **kwargs) method_to_decorate(self, *args, **kwargs) super(type(self), self).save(*args, ** kwargs) homecoming wrapper class the_image_abstract(models.model): class meta: abstract = true create_time = models.datetimefield(editable=false) class avatar(the_image_abstract): #i'm using track avatar class in template. there should improve way. user = models.onetoonefield(user, related_name='avatar') @save_decorator def save(self, *args, **kwargs): "my stuff here" pass
this works when avatar saved or modified in admin page. raises internal error when avatar saved formset in inline of model (formset worked before adding decorator). going wrong here? saw posts people receiving error when using postgres , using postgres don't think case caused postgres.
request method: post request url: http://localhost/admin/auth/normal_user/add/ django version: 1.4.3 exception type: internalerror exception value: current transaction aborted, commands ignored until end of transaction block exception location: /home/eras/projects/kart/venv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py in execute_sql, line 912 python executable: /home/eras/projects/kart/venv/bin/python python version: 2.7.3
any help appreciated!
thanks,
eras
ok found reason why happening. had decorator trying save model before non null fields had no default value set. i'm not still sure why causing error when saving new objects in admin inlines (formset). setting mandatory fields value before running custom save function solved problem.
python django
No comments:
Post a Comment