Development on bottle.py + mongoengine. There is a base class:

class BaseMetaDocument(Document): _id = ObjectIdField(required = True, title = u'ИД', readonly = True, order = 0) unit = StringField(required = True, max_length = 255, default = settings.UNIT, title = u'Наша организация', readonly = True, order = 1000) name = StringField(required = True, unique_with = 'unit', max_length = 255, title = u'Наименование', order = 10) active = BooleanField(required = True, default = True, title = u'Состояние', order = 20) meta = { 'abstract': True, 'allow_inheritance': True } 

from which a subclass is then created, for example:

  class iGroup(BaseMetaDocument): parent = ReferenceField('self', title = u'Родительская группа', order = 100) public = BooleanField(required = True, default = True, title = u'Публичная', order = 101) #?!# users = ListField(ReferenceField(iUser, reverse_delete_rule = PULL), title = u'Список пользователей', order = 102) meta = { 'collection': 'iGroup' } 

To display on the form, I collect the dictionary:

  for k, v in objectInfo._fields.iteritems(): info = {} ftype = type(v) info = dict(title = v.title, name = k, type = ftype.__name__, value = objectInfo[k], required = v.required, readonly = getattr(v, 'readonly', False), order = getattr(v, 'order', 500)) newObjectInfo.append(info) 

But I get the error: Cannot resolve the field "id". If the _id = ObjectIdField field is removed from the base class (required = True, title = u'ID ', readonly = True, order = 0) , then everything works correctly, the only thing you need to separately add _id to the dictionary separately. which is not very convenient.

  • Try using the variable name without underscore. - mkkik
  • This is a basic field, I tried, errors appear at a level "higher." - Ildus N.
  • Actually, I tried to override _id. in order to add the attributes "title = u'ID ', readonly = True, order = 0". Can this be done differently ?! - Ildus N.

0