开发者

force creating object when using raw_id_fields in Django

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜