Django ModelForm with extra fields that are not in the model

后端 未结 7 558
甜味超标
甜味超标 2021-01-31 02:00

I have done a ModelForm adding some extra fields that are not in the model. I use these fields for some calcualtions when saving the form.

The extra fie

7条回答
  •  忘了有多久
    2021-01-31 02:39

    First, you shouldn't have artist_id and artist fields. They are build from the model. If you need some artist name, add artist_name field, that is CharField.

    Furthermore, you are trying to retrieve something from cleaned_data inside clean value. There might not be data you need - you should use values from self.data, where is data directly from POST.

提交回复
热议问题