Skip to content

Becomes compatible with latest versions of mongoengine #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions mongodbforms/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,11 @@ def __new__(cls, name, bases, attrs):
opts = new_class._meta = ModelFormOptions(
getattr(new_class, 'Meta', None)
)

if not hasattr(new_class, 'declared_fields'):
if hasattr(new_class, 'base_fields'):
new_class.declared_fields = new_class.base_fields

if opts.document:
formfield_generator = getattr(opts,
'formfield_generator',
Expand All @@ -323,6 +328,7 @@ def __new__(cls, name, bases, attrs):
formfield_generator)
# make sure opts.fields doesn't specify an invalid field
none_document_fields = [k for k, v in fields.items() if not v]

missing_fields = (set(none_document_fields) -
set(new_class.declared_fields.keys()))
if missing_fields:
Expand All @@ -333,7 +339,9 @@ def __new__(cls, name, bases, attrs):
# Override default model fields with any custom declared ones
# (plus, include all the other declared fields).
fields.update(new_class.declared_fields)

else:

fields = new_class.declared_fields

new_class.base_fields = fields
Expand Down
2 changes: 1 addition & 1 deletion mongodbforms/fieldgenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def get_field_label(self, field):
return ''

def get_field_help_text(self, field):
if field.help_text:
if hasattr(field, 'help_text') and field.help_text:
return field.help_text
else:
return ''
Expand Down