I am trying to take a modelformset, then process the records that have been changed after the form is submitted. For new records, I need to do certain action like set one form field equal to a hidden field and add some time stamps. For edited records, I do not need to do these actions, just to save the model's edited data. For unchaged records, I would like to keep the default behavior: ignore them.
I have tried lots of things to do this. I found some code suggesting to subclass the BaseModelFormSet, and then overwrite the methods "save_new" and "save_existing." I tried this in my forms.py, but I am getting some problems - the form in this instance is a boolean (so says the debug template, anyway), and so i cannot say something like form.field1 = form.hiddenfield, or form.timestamp = datetime.now(). I also dug into the models.py of django.forms.models, and was able to see that these methods exist but are empty. I found some other methods called save_new_objects and save_existing_objects. Obviously I tried these and they did not work for me, but this could be because I am passing them the wrong information or the right information in an incorrect manner.
I am now trying to call other existing methods that I found in django.forms.models from within the views.py, instead of editing these methods themselves. I have tried saying something like:
for existing_object in form:
form.save()
for new_object in form:
form.programmer = request.user
form.hiddenfield1 = form.field2
form.timestamp = datetime.now()
form.save()
but it seems that this "existing_object" does not exclude new objects from my logic. So I am at a loss.
In the end, what I think I need is to find a way to either: 1) perform an action on edited forms from a modelformset in my views.py, or 2) a way to define processing logic involving the manipulation of form data in the save_new or save_existing methods by subclassing basemodelformset.
Any help would be greatly appreciated. I am relatively new to django (this is my first project but I have been learning it for about a month now) and so I may be wildly misguided. Sorry if that is the case.