How to trigger a function with an update view

33 views
Skip to first unread message

MH

unread,
Feb 12, 2022, 4:09:55 PM2/12/22
to Django users
Hi

I have an update view which enables me via a form to update the data for a particular model object instance (as it should do). However, when a particular field gets changed I would not only need to update the fields in the database, but I would need the save routine of the update view to trigger a computation and to update another field with a new value as well. How can this be done?

Best regards

Sebastian Jung

unread,
Feb 13, 2022, 3:33:16 AM2/13/22
to django...@googlegroups.com
Hello,

You overwright in forms.py in your form save()

Example:

def save(self, commit=True):
    instance = super(MyForm, self).save(commit=False)
    instance.flag1 = 'flag1' in self.cleaned_data['multi_choice'] # etc
    if commit:
        instance.save()
    return instance

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8aa6e29d-77a9-4658-b0a6-f7d8b8af7993n%40googlegroups.com.

MH

unread,
Feb 13, 2022, 5:33:09 AM2/13/22
to Django users
Thanks for the specific advice. I will try that.
Reply all
Reply to author
Forward
0 new messages