I have a string field inside an embedded document and override this field to be a selected field. After overriding, I add an empty list of choices as an argument to the selcted field.
The issue is that on form access we try to add some dynamic choices to the selected field, but for some reason, this fails.
How can we add some dynamic choices? I need to do this using some kind of preprocessor because the data is from DB that loads just after all the models.
class:
class BadgeDoc(EmbeddedDocument):
parent_id = ObjectIdField()
name = StringField()
display_text = StringField()
color = StringField()
extra_style = StringField()
service = ObjectIdField()
badge_type = StringField()
class PresentationCategory(Presentation):
product = ReferenceField('ProductType')
article = EmbeddedDocumentField(Article)
show_video_review = BooleanField()
show_video_reviews_count = IntField(default=0)
badge = ListField(EmbeddedDocumentField(BadgeDoc))
view:
class PresentationView(NewPresentationView):
form_subdocuments = {
'badge': {
'form_subdocuments': {
None:
{
'form_excluded_columns': ('name', 'display_text', 'color', 'extra_style', 'service',
'badge_type'),
'form_overrides': {
'parent_id': admin.form.fields.Select2Field,
},
'form_args': {
'parent_id': {'choices': []}
}
}
}
}
}