def _init_pk(self): """ Adds a wrapper around the documents pk field. The wrapper object gets the attributes django expects on the pk field, like name and attname. The function also adds a _get_pk_val method to the document. """ if self.id_field is None: return try: pk_field = getattr(self.document, self.id_field) self._pk = PkWrapper(pk_field) self._pk.name = self.id_field self._pk.attname = self.id_field self._pk_name = self.id_field self.document._pk_val = getattr(self.document, self.pk_name) # avoid circular import from mongodbforms.util import patch_document def _get_pk_val(self): return self._pk_val patch_document(_get_pk_val, self.document) except AttributeError: return
def results(cl): """ Just like the one from Django. Only we add a serializable_value method to the document, because Django expects it and mongoengine doesn't have it. """ if cl.formset: for res, form in zip(cl.result_list, cl.formset.forms): patch_document(serializable_value, res) yield ResultList(form, items_for_result(cl, res, form)) else: for res in cl.result_list: patch_document(serializable_value, res) res._meta = res._admin_opts yield ResultList(None, items_for_result(cl, res, None))