开发者

Django non-rel - How to create forms with EmbeddedModelField in the model?

开发者 https://www.devze.com 2023-04-02 21:12 出处:网络
I have setup for Django non-rel with Mongodb as backend. 开发者_高级运维In models, I used EmbeddedModelField for quite a few times as I love those concepts of Non relational DBs. But, when it comes to

I have setup for Django non-rel with Mongodb as backend. 开发者_高级运维In models, I used EmbeddedModelField for quite a few times as I love those concepts of Non relational DBs. But, when it comes to rendering forms. I got stuck,

I created Form as normal form of Django but django showing Type error {model} in the title bar.

Has anybody know how can I create form fields for EmbeddedModelField in Django non-rel?


Just implement a formfield class by yourself.

  1. implement formfield in forms.py
  2. specify which form you want to use with this model in models.py

implementing a formfield is a piece of cake, you just need to implement these two methods in the class:

  1. to_python(self, value)
  2. prepare_value(self, value)

If you implement it with inheritance of old formfield class, you could use the widget attached on that formfield. (widget means the UI will be rendered on the webpage by template system)

Reference for implementing formfield: How to use ListFields in Django's admin

And you could implement your own widget by overriding the original widget of a formfield.

For instance, take a look at django documentations: Django docs - widgets

0

精彩评论

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