Skip to content
Advertisement

Can you iterate through model fields when you overwrite the save() method in django?

I’m calling a custom save method in my model. The save method is designed to produce some values in the model based on the content of a TextField. This content is stored in a dictionary, and is generated correctly.

I’m trying to write a for loop to store the values of the dictionary. The keys correspond to the model field names:

JavaScript

The value is not stored in the corresponding field. Do I need to use setattr here instead?

Advertisement

Answer

Try this:

JavaScript
Advertisement