开发者

force creating object when using raw_id_fields in Django

开发者 https://www.devze.com 2023-01-27 12:46 出处:网络
I\'m using raw_id_fields in my admin.py to change the ForeignKey\'s select box to an input box. When saving the form, it checks if the object that I wrote in the ForeignKey box exists, if not, it rai

I'm using raw_id_fields in my admin.py to change the ForeignKey's select box to an input box.

When saving the form, it checks if the object that I wrote in the ForeignKey box exists, if not, it raises an error sa开发者_如何学编程ying "Select a valid choice. That choice is not one of the available choices."

What I want to do is skipping this validation and creating the object directly if it doesn't exist.

Any idea to do that?

Thank you very much


you can overwrite your model's save() by adding codes to create the object directly if it doesn't exist.

0

精彩评论

暂无评论...
验证码 换一张
取 消