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.
- implement formfield in forms.py
- 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:
to_python(self, value)
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
精彩评论