我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用django.db.models.py()。
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
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')
def get_unread_nums(self): from operation.models import UserMessage # ???????????operation/models.py???? return UserMessage.objects.filter(user=self.id, has_read=False).count()