Python django.contrib.auth.models.User 模块,add_to_class() 实例源码

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

项目:django-changeset    作者:beachmachine    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        super(RevisionModelMixin, self).__init__(*args, **kwargs)
        # register the get method for related_name on the user model
        related_name_user = getattr(self._meta, 'related_name_user', '')

        if related_name_user != '':
            User.add_to_class("get_" + related_name_user,
                              lambda user: # user will be set by the calling object afterwards
                              get_all_objects_created_by_user(user=user,
                                                              object_type=ContentType.objects.get_for_model(self)))