Closed bool-dev closed 10 years ago
I think the sintax is a bit different, I also tried and no luck, it does not works also "form_rules" do not work.
https://github.com/pythonhub/quokka/blob/master/quokka/modules/posts/admin.py#L80
But form_columns and form_ajax_refs worked well.
form_subdocuments = {
'contents': {
'form_subdocuments': {
None: {
'form_columns': ('content', 'caption', 'purpose', 'order'),
'form_ajax_refs': {
'content': {
'fields': ['title', 'long_slug', 'summary']
}
}
}
}
},
}
I cant understand the "None" as key...
form_widget_args
are probably not passed to child models (I'm sure it is not passed to inline models - there's bug for that), I will check.
@rochacbruno:
None
in form_subdocuments
is only necessary if you have ListField
with child field. Unfortunately, it is limitation of flask-mongoengine form scaffolding functionality - it creates child field for ListField
with None
as name.
Currently, I'm not sure how to make it look better.
Update: I'm slightly busy this week, will go over all issues this weekend.
@mrjoes , I want to help, was trying to figure out a solution but haven't come up with anything yet. If you could tell me which files to look at, i could continue trying.
@rochacbruno what mrjoes said, 'None' is for ListFields.
Understood! thanks.
So, I think that is the problem with form_rules, need to check if it is being passed to subdocumments inside a ListField.
Very sorry it took that long - I was very busy lately.
@mrjoes Thanks for this. :+1: Better late than never! Will also check and report if there is anything missing.
Hate to reopen this, but figured the issue is what's being talked about here. From what I can tell it's still a problem with EmbeddedDocumentField (ie form_subdocuments). When I attempt to set 'form_widget_args' on the subdocument it still does not work (though form_columns and form_args works fine). My definition is:
form_subdocuments = {
'metadata': {
'form_columns': ('artist', 'album',),
'form_widget_args': {
'artist': { 'rows': 50 }
}
}
}
The form_widget_args
section does not appear to get set. Wonder if I'm doing something wrong. The field 'metadata' is just a db.EmbeddedDocumentField(MetadataDoc), so not a list.
(This is with 1.0.8, but also tried with the master branch and got the same results)
Actually, this is bizarre. If also add a form_rules
key then it all works fine! But I don't understand why form_rules are needed in order to get the form_widget_args
to work. Basically the following works:
form_subdocuments = {
'metadata': {
'form_rules`: ('artist', 'album',)
'form_widget_args': {
'artist': { 'rows': 50 }
}
}
}
One workaround for this is to add a read-only flag to subdocuments at the database level. To do this, add SQLAlchemy's viewonly=True
configuration to the relationship in your model definition.
children = relationship('Category', backref=db.backref('parent', remote_side=[id]), viewonly=True)
@cybertoast Can you tell me how to get worked Ckeditor widget for name in EmbeddedDocument
class EmbeddedService(EmbeddedDocument): name = StringField()
class Service(Document): ... services = ListField(EmbeddedDocumentField(EmbeddedService)) ...
I just did it :D
@ufo911 thanks!
I have been trying to add form_widget_args to a field in a mongonengine EmbeddedDocument, using:
but it does not work. Is this not yet supported? p.s. - For main document fields widget_args work perfectly.
Edit: Also tried, without any luck: