@app.task
def foo(idx):
print("This is iteration {}".format(idx))
def save_model(self, request, obj, form, change):
data = request.POST
result = super(Model, self).save_model(request, obj, form, change)
for pk in data['_models_changed']:
transaction.on_commit(lambda: foo(pk))
"This is iteration 1"
"This is iteration 2"
"This is iteration 3"
"This is iteration 4"
"This is iteration 4"
"This is iteration 4"
"This is iteration 4"
"This is iteration 4"
I'm not too familiar with Celery, but I think that for loop continuously keeps changing transaction's commit event handler. Maybe you are looking for something like transaction.commit instead of on_commit?
--
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...@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/91e87fb4-69e2-4b4e-bd6b-704eb7567026%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi,
I think your problem is to use POST['_models_changed']. Django
uses specialized version of dictionary there which return _last_
value from list. You need to use special "get_list()" method to
get whole list of objects.
--
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...@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/91e87fb4-69e2-4b4e-bd6b-704eb7567026%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
-- Jani Tiainen