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 'id_field' in self._meta:
            self.pk_name = self._meta['id_field']
            pk_field = getattr(self.document, self.pk_name)
        else:
            pk_field = None
        self.pk = PkWrapper(pk_field)

        def _get_pk_val(obj):
            return obj.pk
        patch_document(_get_pk_val, self.document, False)  # document is a class...

        if pk_field is not None:
            self.pk.name = self.pk_name
            self.pk.attname = self.pk_name
        else:
            self.pk.fake = True
            # this is used in the admin and used to determine if the admin
            # needs to add a hidden pk field. It does not for embedded fields.
            # So we pretend to have an editable pk field and just ignore it otherwise
            self.pk.editable = True
dataset/ETHPy150Open jschrewe/django-mongodbforms/mongodbforms/documentoptions.py/DocumentMetaWrapper._init_pk/original