Python django.db.models 模块,py() 实例源码

我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用django.db.models.py()

项目:morango    作者:learningequality    | 项目源码 | 文件源码
def serialize(self):
        """All concrete fields of the ``SyncableModel`` subclass, except for those specifically blacklisted, are returned in a dict."""
        # NOTE: code adapted from https://github.com/django/django/blob/master/django/forms/models.py#L75
        opts = self._meta

        data = {}
        for f in opts.concrete_fields:
            if f.attname in self.morango_fields_not_to_serialize:
                continue
            if f.attname in self._morango_internal_fields_not_to_serialize:
                continue
            # case if model is morango mptt
            if f.attname in getattr(self, '_internal_mptt_fields_not_to_serialize', '_internal_fields_not_to_serialize'):
                continue
            if hasattr(f, 'value_from_object_json_compatible'):
                data[f.attname] = f.value_from_object_json_compatible(self)
            else:
                data[f.attname] = f.value_from_object(self)
        return data
项目:zing    作者:evernote    | 项目源码 | 文件源码
def get_terminology_project(self, language_id):
        # FIXME: the code below currently uses the same approach to determine
        # the 'terminology' kind of a project as 'Project.is_terminology()',
        # which means it checks the value of 'checkstyle' field
        # (see pootle_project/models.py:240).
        #
        # This should probably be replaced in the future with a dedicated
        # project property.
        return self.get(language=language_id,
                        project__checkstyle='terminology')
项目:StudyOnline    作者:yipwinghong    | 项目源码 | 文件源码
def get_unread_nums(self):

        from operation.models import UserMessage    # ???????????operation/models.py????
        return UserMessage.objects.filter(user=self.id, has_read=False).count()