• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python simple_history.register函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中simple_history.register函数的典型用法代码示例。如果您正苦于以下问题:Python register函数的具体用法?Python register怎么用?Python register使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了register函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_reregister

 def test_reregister(self):
     register(Restaurant, manager_name='again')
     register(User, manager_name='again')
     self.assertTrue(hasattr(Restaurant, 'updates'))
     self.assertFalse(hasattr(Restaurant, 'again'))
     self.assertTrue(hasattr(User, 'histories'))
     self.assertFalse(hasattr(User, 'again'))
开发者ID:dgreisen-cfpb,项目名称:django-simple-history,代码行数:7,代码来源:tests.py


示例2: setup_m2m_history

 def setup_m2m_history(self, cls):
     m2m_history_fields = self.m2m_fields
     if m2m_history_fields is ALL_M2M_FIELDS:
         for field in cls._meta.many_to_many:
             field = getattr(cls, field.name).field
             assert isinstance(field, models.fields.related.ManyToManyField), \
                 ('%s must be a ManyToManyField' % field.name)
             if not sum([
                     isinstance(item, HistoricalRecords) for item in field.remote_field.through.__dict__.values()
             ]):
                 through_model = field.remote_field.through
                 if through_model._meta.auto_created and not_registered(through_model):
                     through_model.history = HistoricalRecords()
                     register(through_model)
     elif m2m_history_fields:
         assert (isinstance(m2m_history_fields, list) or isinstance(m2m_history_fields, tuple)), \
             'm2m_history_fields must be a list or tuple'
         for field_name in m2m_history_fields:
             field = getattr(cls, field_name).field
             assert isinstance(field, models.fields.related.ManyToManyField), \
                 ('%s must be a ManyToManyField' % field_name)
             if not sum([
                     isinstance(item, HistoricalRecords) for item in field.remote_field.through.__dict__.values()
             ]):
                 through_model = field.remote_field.through
                 if through_model._meta.auto_created and not_registered(through_model):
                     through_model.history = HistoricalRecords()
                     register(through_model)
开发者ID:emergence,项目名称:django-simple-history,代码行数:28,代码来源:models.py


示例3: contribute_to_class

    def contribute_to_class(self, cls, name):
        self.manager_name = name
        self.module = cls.__module__
        models.signals.class_prepared.connect(self.finalize, sender=cls)
        setattr(cls, 'simple_history_manager', name)

        def save_without_historical_record(self, *args, **kwargs):
            """Caution! Make sure you know what you're doing before you use this method."""
            self.skip_history_when_saving = True
            ret = self.save(*args, **kwargs)
            del self.skip_history_when_saving
            return ret
        setattr(cls, 'save_without_historical_record', save_without_historical_record)

        # Injecting HistoricalRecords into ManyToManyFields' intermediate tables ('through' models)
        if hasattr(cls, 'm2m_history_fields'):
            m2m_history_fields = getattr(cls, 'm2m_history_fields', None)
            assert (isinstance(m2m_history_fields, list)
                or  isinstance(m2m_history_fields, tuple)), 'm2m_history_fields must be a list or tuple'
            for field_name in m2m_history_fields:
                field = getattr(cls, field_name).field
                assert isinstance(field, models.fields.related.ManyToManyField), ('%s must be a ManyToManyField' % field_name)
                if not sum([isinstance(item, HistoricalRecords) for item in field.rel.through.__dict__.values()]):
                    field.rel.through.history = HistoricalRecords()
                    simple_history.register(field.rel.through)
开发者ID:oramadev,项目名称:orama-django-simple-history,代码行数:25,代码来源:models.py


示例4: setup_m2m_history

 def setup_m2m_history(self, cls):
     m2m_history_fields = self.m2m_fields
     if m2m_history_fields:
         assert (isinstance(m2m_history_fields, list) or isinstance(m2m_history_fields, tuple)), 'm2m_history_fields must be a list or tuple'
         for field_name in m2m_history_fields:
             field = getattr(cls, field_name).field
             assert isinstance(field, models.fields.related.ManyToManyField), ('%s must be a ManyToManyField' % field_name)
             if not sum([isinstance(item, HistoricalRecords) for item in field.rel.through.__dict__.values()]):
                 field.rel.through.history = HistoricalRecords()
                 register(field.rel.through)
开发者ID:Kyruus,项目名称:django-simple-history,代码行数:10,代码来源:models.py


示例5: finalize

    def finalize(self, sender, **kwargs):
        try:
            hint_class = self.cls
        except AttributeError:  # called via `register`
            pass
        else:
            if hint_class is not sender:  # set in concrete
                if not (self.inherit and issubclass(sender, hint_class)):
                    return  # set in abstract
        if hasattr(sender._meta, 'simple_history_manager_attribute'):
            raise exceptions.MultipleRegistrationsError(
                '{}.{} registered multiple times for history tracking.'.format(
                    sender._meta.app_label,
                    sender._meta.object_name,
                )
            )
        if sender._meta.proxy:
            original_class = [base_class for base_class in sender.__bases__ if base_class._meta.abstract is False][0]
            # Parent model must be registered before the proxy model is
            if not_registered(original_class):
                # Ignore the `app` kwarg, since the proxy model may be in a different app than the original model
                register_kwargs = {
                    'manager_name': self.manager_name,
                    'records_class': self.__class__,
                    'verbose_name': self.user_set_verbose_name,
                    'bases': self.bases,
                    'user_related_name': self.user_related_name,
                    'm2m_fields': self.m2m_fields,
                }
                register(original_class, **register_kwargs)
            # Proxy models use their parent's history model
            history_model = getattr(sender, self.manager_name).model
        else:
            history_model = self.create_history_model(sender)
            module = importlib.import_module(self.module)
            setattr(module, history_model.__name__, history_model)
        # The HistoricalRecords object will be discarded,
        # so the signal handlers can't use weak references.
        models.signals.post_save.connect(self.post_save, sender=sender,
                                         weak=False)
        models.signals.pre_delete.connect(self.pre_delete, sender=sender,
                                          weak=False)
        models.signals.post_delete.connect(self.post_delete, sender=sender,
                                           weak=False)
        models.signals.m2m_changed.connect(self.m2m_changed, sender=sender, weak=False)

        descriptor = HistoryDescriptor(history_model)
        setattr(sender, self.manager_name, descriptor)
        sender._meta.simple_history_manager_attribute = self.manager_name
开发者ID:emergence,项目名称:django-simple-history,代码行数:49,代码来源:models.py


示例6: Poll

from simple_history import register


class Poll(models.Model):
    question = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')

    history = HistoricalRecords()


class Choice(models.Model):
    poll = models.ForeignKey(Poll)
    choice = models.CharField(max_length=200)
    votes = models.IntegerField()

register(Choice)


class Place(models.Model):
    name = models.CharField(max_length=100)


class Restaurant(Place):
    rating = models.IntegerField()

    updates = HistoricalRecords()


class Person(models.Model):
    name = models.CharField(max_length=100)
开发者ID:dgreisen-cfpb,项目名称:django-simple-history,代码行数:30,代码来源:models.py


示例7: HistoricalRecords

    level = models.IntegerField()
    date = models.DateTimeField()

    history = HistoricalRecords()

    @property
    def _history_date(self):
        return self.date


class Choice(models.Model):
    poll = models.ForeignKey(Poll)
    choice = models.CharField(max_length=200)
    votes = models.IntegerField()

register(Choice)


class Voter(models.Model):
    user = models.ForeignKey(User)
    choice = models.ForeignKey(Choice, related_name='voters')


class HistoricalRecordsVerbose(HistoricalRecords):
    def get_extra_fields(self, model, fields):
        def verbose_str(self):
            return '%s changed by %s as of %s' % (
                self.history_object, self.history_user, self.history_date)

        extra_fields = super(
            HistoricalRecordsVerbose, self).get_extra_fields(model, fields)
开发者ID:g10f,项目名称:django-simple-history,代码行数:31,代码来源:models.py


示例8: institutionAdmin

class institutionAdmin (SimpleHistoryAdmin):
    list_display = ('user', 'department')
    class Meta:
        model = Institution

class patientIdAdmin (SimpleHistoryAdmin):
    list_display = ('user', 'patient_id')
    class Meta:
        model = Patient_id

class aggregateAdmin (SimpleHistoryAdmin):
    list_display = ('center_id','name_of_center', 'author', 'pub_date')
    class Meta:
        model = Ext_centers

register(User, inherit=True)
register(Group, inherit=True)

#admin.site.register(User, SimpleHistoryAdmin)
admin.site.register(Institution, institutionAdmin)
admin.site.register(Patient_id, patientIdAdmin)
admin.site.register(Demographic, DemographicsAdmin)
admin.site.register(Diagnosis, DiagnosisAdmin)
admin.site.register(DiagnosisOption,diag_optAdmin)
admin.site.register(A_b_sickle_thal,a_b_sickle_Admin)
admin.site.register(Redcell_enzyme_dis,redcell_enzAdmin)
admin.site.register(Redcell_membrane_dis,redcell_memb_Admin)
admin.site.register(Cong_dyseryth_anaemia,cong_dyserAdmin)
admin.site.register(icd_10, icd10Admin)
admin.site.register(orphaCodes, orphaAdmin)
admin.site.register(Pregnancy,pregnancyAdmin)
开发者ID:zinonas,项目名称:project_myTIF,代码行数:31,代码来源:admin.py


示例9: HistoricalRecords

    level = models.IntegerField()
    date = models.DateTimeField()

    history = HistoricalRecords()

    @property
    def _history_date(self):
        return self.date


class Choice(models.Model):
    poll = models.ForeignKey(Poll)
    choice = models.CharField(max_length=200)
    votes = models.IntegerField()

register(Choice)


class Place(models.Model):
    name = models.CharField(max_length=100)


class Restaurant(Place):
    rating = models.IntegerField()

    updates = HistoricalRecords()


class Person(models.Model):
    name = models.CharField(max_length=100)
开发者ID:DAV3HIT3,项目名称:django-simple-history,代码行数:30,代码来源:models.py


示例10: actual_decorator

 def actual_decorator(model):
     simple_history.register(model, **kwargs)
     return model
开发者ID:gitter-badger,项目名称:chcemvediet,代码行数:3,代码来源:history.py


示例11: test_registering_with_tracked_abstract_base

    def test_registering_with_tracked_abstract_base(self):
        class TrackedWithAbstractBaseToRegister(TrackedAbstractBaseA):
            pass

        with self.assertRaises(exceptions.MultipleRegistrationsError):
            register(TrackedWithAbstractBaseToRegister)
开发者ID:StepicOrg,项目名称:django-simple-history,代码行数:6,代码来源:test_models.py


示例12: ExternalModel4

from __future__ import unicode_literals

from django.db import models
from simple_history import register


class ExternalModel4(models.Model):
    name = models.CharField(max_length=100)

    class Meta:
        app_label = 'external'

register(ExternalModel4, app='simple_history.tests',
         manager_name='histories')
开发者ID:DAV3HIT3,项目名称:django-simple-history,代码行数:14,代码来源:model4.py


示例13: test_registering_with_tracked_abstract_base

 def test_registering_with_tracked_abstract_base(self):
     with self.assertRaises(exceptions.MultipleRegistrationsError):
         register(InheritTracking4)
开发者ID:emergence,项目名称:django-simple-history,代码行数:3,代码来源:tests.py


示例14: HistoricalRecords

    date = models.DateTimeField()

    history = HistoricalRecords(cascade_delete_history=True)

    @property
    def _history_date(self):
        return self.date


class Choice(models.Model):
    poll = models.ForeignKey(Poll, on_delete=models.CASCADE)
    choice = models.CharField(max_length=200)
    votes = models.IntegerField()


register(Choice)


class Voter(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    choice = models.ForeignKey(Choice, on_delete=models.CASCADE, related_name="voters")

    def __str__(self):
        return "Voter object"


class HistoricalRecordsVerbose(HistoricalRecords):
    def get_extra_fields(self, model, fields):
        def verbose_str(self):
            return "%s changed by %s as of %s" % (
                self.history_object,
开发者ID:treyhunner,项目名称:django-simple-history,代码行数:31,代码来源:models.py


示例15: register

from django.db import models
from django.utils import timezone
from django.utils.http import urlquote
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin, BaseUserManager
from django.contrib.auth.models import User

from django.core.urlresolvers import reverse
from django.template.defaultfilters import slugify

from .choices import SEX_TYPE 
from simple_history import register

register(User)


class CustomUserManager(BaseUserManager):

    def _create_user(self, email, password, is_staff, is_superuser, **extra_fields):
        now = timezone.now()
        if not email:
            raise ValueError('The given email must be set')
        email = self.normalize_email(email)
        user = self.model(email=email, is_staff=is_staff, is_superuser=is_superuser, last_login=now, date_joined=now, **extra_fields)
        user.set_password(password)
        user.save(using=self._db)
        return user

    def create_user(self,  password=None, **extra_fields):
        return self._create_user(email, password, False, False, **extra_fields)
开发者ID:makudesu,项目名称:bnhsproject,代码行数:30,代码来源:models.py


示例16: LinkMan

from django.contrib.auth.models import AbstractUser
from django.db import models
from simple_history import register
from baseapp.models import BaseModel

# Create your models here.


class LinkMan(BaseModel):
    user_real_name = models.CharField(max_length=20)

    def __str__(self):
        return str(self.user_real_name)


class MyUser(AbstractUser, LinkMan):
    online_hours = models.IntegerField(default=0)

    def __str__(self):
        return str(self.user_real_name)

register(LinkMan)
register(MyUser)
开发者ID:wwwcs59,项目名称:historicalproject,代码行数:23,代码来源:models.py


示例17: ExternalModel

    class Meta:
        abstract = True
        app_label = "external"


class ExternalModel(models.Model):
    name = models.CharField(max_length=100)
    history = HistoricalRecords()


class ExternalModelRegistered(models.Model):
    name = models.CharField(max_length=100)


register(ExternalModelRegistered, app="simple_history.tests", manager_name="histories")


class ExternalModelWithCustomUserIdField(models.Model):
    name = models.CharField(max_length=100)
    history = HistoricalRecords(history_user_id_field=models.IntegerField(null=True))


class Poll(models.Model):
    """Test model for same-named historical models

    This model intentionally conflicts with the 'Polls' model in 'tests.models'.
    """

    history = HistoricalRecords(user_related_name="+")
开发者ID:treyhunner,项目名称:django-simple-history,代码行数:29,代码来源:models.py


示例18: ready

 def ready(self):
     register(MyClass)
     register(MyClassAnother)
开发者ID:wwwcs59,项目名称:historicalproject,代码行数:3,代码来源:apps.py


示例19: test_accessor_default

 def test_accessor_default(self):
     register(UserAccessorDefault)
     assert not hasattr(User, 'historicaluseraccessordefault_set')
开发者ID:g10f,项目名称:django-simple-history,代码行数:3,代码来源:test_models.py


示例20: test_accessor_override

 def test_accessor_override(self):
     register(UserAccessorOverride,
              user_related_name='my_history_model_accessor')
     assert hasattr(User, 'my_history_model_accessor')
开发者ID:g10f,项目名称:django-simple-history,代码行数:4,代码来源:test_models.py



注:本文中的simple_history.register函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python models.HistoricalRecords类代码示例发布时间:2022-05-27
下一篇:
Python testing_utils.create_thread函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap