In my ModelForm’s save() method I am accessing self.changed_data and I would like to do something like:
changes_moderated_dict.update(dict(
[(i, staff.profile.user.__dict__[i])
for i in changed_data
if i in staff.profile.user.__dict__]))
which updates changes_moderated_dict with staff.profile.user key/value pairs if the key is found in changed_data. changes_moderated_dict is basically used to store all the field changes made to this particular model inside the form (for later processing and serialization).
This works all fine as long as the staff.profile.user is not a foreign key relationship in which case the filed name has a _id suffix and would not match up with the self.changed_data field name which is the attribute name as it appears in the model (without _id).
Is there a way do resolve the foreign key attribute inside a model’s __dict__ to it’s actual name so that the above method still works?
I’m not sure what the goal of accessing
user.__dict__is, but if it is to check the model fields you can do something like this: