当前位置: 首页>>代码示例>>Python>>正文


Python GenericRelation.contribute_to_class方法代码示例

本文整理汇总了Python中django.contrib.contenttypes.generic.GenericRelation.contribute_to_class方法的典型用法代码示例。如果您正苦于以下问题:Python GenericRelation.contribute_to_class方法的具体用法?Python GenericRelation.contribute_to_class怎么用?Python GenericRelation.contribute_to_class使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.contrib.contenttypes.generic.GenericRelation的用法示例。


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

示例1: post_through_setup

# 需要导入模块: from django.contrib.contenttypes.generic import GenericRelation [as 别名]
# 或者: from django.contrib.contenttypes.generic.GenericRelation import contribute_to_class [as 别名]
 def post_through_setup(self, cls):
     self.use_gfk = self.through is None or issubclass(self.through, GenericTaggedItemBase)
     self.rel.to = self.through._meta.get_field("tag").rel.to
     self.related = RelatedObject(self.through, cls, self)
     if self.use_gfk:
         tagged_items = GenericRelation(self.through)
         tagged_items.contribute_to_class(cls, "tagged_items")
开发者ID:joestump,项目名称:django-taggit,代码行数:9,代码来源:managers.py

示例2: contribute_to_class

# 需要导入模块: from django.contrib.contenttypes.generic import GenericRelation [as 别名]
# 或者: from django.contrib.contenttypes.generic.GenericRelation import contribute_to_class [as 别名]
 def contribute_to_class(self, cls, name):
     self.name = self.column = name
     self.model = cls
     cls._meta.add_field(self)
     setattr(cls, name, self)
     if self.use_gfk:
         tagged_items = GenericRelation(self.through)
         tagged_items.contribute_to_class(cls, "tagged_items")
开发者ID:strogo,项目名称:django-taggit,代码行数:10,代码来源:managers.py

示例3: post_through_setup

# 需要导入模块: from django.contrib.contenttypes.generic import GenericRelation [as 别名]
# 或者: from django.contrib.contenttypes.generic.GenericRelation import contribute_to_class [as 别名]
 def post_through_setup(self, cls):
     self.use_gfk = (
         self.through is None or issubclass(self.through, GenericChoiceBase)
     )
     self.rel.to = self.through._meta.get_field("poll").rel.to
     if self.use_gfk:
         poll_choices = GenericRelation(self.through)
         poll_choices.contribute_to_class(cls, "poll_choices")
开发者ID:sixpearls,项目名称:django-pollup,代码行数:10,代码来源:managers.py

示例4: post_through_setup

# 需要导入模块: from django.contrib.contenttypes.generic import GenericRelation [as 别名]
# 或者: from django.contrib.contenttypes.generic.GenericRelation import contribute_to_class [as 别名]
 def post_through_setup(self, cls):
     self.use_gfk = (
         self.through is None or issubclass(self.through, GenericTaggedItemBase)
     )
     self.rel.to = self.through._meta.get_field("tag").rel.to
     if self.use_gfk:
         tagged_items = GenericRelation(self.through)
         tagged_items.contribute_to_class(cls, "%s_tagged_items" % cls.__name__.lower())
开发者ID:ryanbagwell,项目名称:django-taggit,代码行数:10,代码来源:managers.py

示例5: post_through_setup

# 需要导入模块: from django.contrib.contenttypes.generic import GenericRelation [as 别名]
# 或者: from django.contrib.contenttypes.generic.GenericRelation import contribute_to_class [as 别名]
 def post_through_setup(self, cls):
     self.related = RelatedObject(cls, self.model, self)
     self.use_gfk = (
         self.through is None or issubclass(self.through, GenericTaggedItemBase)
     )
     self.rel.to = self.through._meta.get_field("tag").rel.to
     self.related = RelatedObject(self.through, cls, self)
     if self.use_gfk:
         self.__class__._related_name_counter += 1
         related_name = '+%d' % self.__class__._related_name_counter
         tagged_items = GenericRelation(self.through, related_name=related_name)
         tagged_items.contribute_to_class(cls, 'tagged_items')
开发者ID:AndrewJHart,项目名称:django-taggit,代码行数:14,代码来源:managers.py

示例6: post_through_setup

# 需要导入模块: from django.contrib.contenttypes.generic import GenericRelation [as 别名]
# 或者: from django.contrib.contenttypes.generic.GenericRelation import contribute_to_class [as 别名]
    def post_through_setup(self, cls):
        self.related = RelatedObject(cls, self.model, self)
        self.use_gfk = (
            self.through is None or issubclass(self.through, GenericTaggedItemBase)
        )
        self.rel.to = self.through._meta.get_field("tag").rel.to
        self.related = RelatedObject(self.through, cls, self)
        if self.use_gfk:
            tagged_items = GenericRelation(self.through)
            tagged_items.contribute_to_class(cls, 'tagged_items')

            for rel in cls._meta.local_many_to_many:
                if isinstance(rel, TaggableManager) and rel.use_gfk and rel != self:
                    raise ValueError('You can only have one TaggableManager per model'
                        ' using generic relations.')
开发者ID:MeirKriheli,项目名称:django-taggit,代码行数:17,代码来源:managers.py

示例7: post_through_setup

# 需要导入模块: from django.contrib.contenttypes.generic import GenericRelation [as 别名]
# 或者: from django.contrib.contenttypes.generic.GenericRelation import contribute_to_class [as 别名]
    def post_through_setup(self, cls):
        self.related = RelatedObject(cls, self.model, self)
        self.use_gfk = (
            self.through is None or issubclass(self.through, GenericTaggedItemBase)
        )
        self.rel.to = self.through._meta.get_field("tag").rel.to
        self.related = RelatedObject(self.through, cls, self)
        if self.use_gfk:
            tagged_items = GenericRelation(self.through)
            tagged_items.contribute_to_class(cls, 'tagged_items')

        for rel in cls._meta.local_many_to_many:
            if rel == self or not isinstance(rel, TaggableManager):
                continue
            if rel.through == self.through:
                raise ValueError('You can\'t have two TaggableManagers with the'
                                 ' same through model.')
开发者ID:grobertson,项目名称:django-taggit,代码行数:19,代码来源:managers.py

示例8: negotiable

# 需要导入模块: from django.contrib.contenttypes.generic import GenericRelation [as 别名]
# 或者: from django.contrib.contenttypes.generic.GenericRelation import contribute_to_class [as 别名]
def negotiable(cls):
    # EXTEND NEGOTIABLE CLASS

    # add the default for mandatory method 'freeze'
    if not hasattr(cls, 'freeze') or not callable(getattr(cls, 'freeze')):
        setattr(cls, 'freeze', freeze)

    # add the mandatory 'creator' property
    if not hasattr(cls, 'creator'):
        setattr(cls, 'creator', creator)

    # add the generic relation field to negotiable class
    negotiations = GenericRelation(Negotiation, object_id_field='content_pk', content_type_field='content_type')
    negotiations.contribute_to_class(cls, 'negotiations')

    # add the negotiation property
    setattr(cls, 'negotiation', negotiation)

    # add the negotiate method
    setattr(cls, 'negotiate', negotiate)

    # add the status_for method
    setattr(cls, 'status_for', status_for)

    # add the accept method
    setattr(cls, 'accept', accept)

    # add the cancel method
    setattr(cls, 'cancel', cancel)

    # add the counter_proposal method
    setattr(cls, 'counter_proposal', counter_proposal)

    # add the modify_proposal method
    setattr(cls, 'modify_proposal', modify_proposal)

    # add the is_negotiating property
    setattr(cls, 'is_negotiating', is_negotiating)

    # add the is_accepted property
    setattr(cls, 'is_accepted', is_accepted)

    # add the is_cancelled property
    setattr(cls, 'is_cancelled', is_cancelled)

    # add the is_seller method
    setattr(cls, 'is_seller', is_seller)

    # add the is_client method
    setattr(cls, 'is_client', is_client)

    # add the last_proposal_from method
    setattr(cls, 'last_proposal_from', last_proposal_from)

    # add the last_counterpart_proposal_for method
    setattr(cls, 'last_counterpart_proposal_for', last_counterpart_proposal_for)

    # add the last_client_proposal property
    setattr(cls, 'last_client_proposal', last_client_proposal)

    # add the last_seller_proposal property
    setattr(cls, 'last_seller_proposal', last_seller_proposal)

    # add the initiator property
    setattr(cls, 'initiator', initiator)

    # add the last_updater property
    setattr(cls, 'last_updater', last_updater)

    # add the is_last_updater method
    setattr(cls, 'is_last_updater', is_last_updater)

    # add the history method
    setattr(cls, 'history', history)

    # add the negotiation_options method
    setattr(cls, 'negotiation_options', negotiation_options)

    # EXTEND NEGOTIABLE CLASS'S MANAGERS AND QUERYSETS

    cls._meta.concrete_managers.sort()
    managers = [(mgr_name, manager) for _, mgr_name, manager in cls._meta.concrete_managers]

    setattr(cls, '_default_manager', None)  # clean the default manager
    setattr(cls._meta, 'concrete_managers', [])  # clean the managers

    for mgr_name, manager in managers:

        class ExtendedNegotiableManager(ExtendedNegotiableManagerMixin, manager.__class__):

            class ExtendedNegotiableQueryset(ExtendedNegotiableQuerysetMixin, manager.get_queryset().__class__):
                pass

            def get_queryset(self):
                return self.ExtendedNegotiableQueryset(self.model, using=self._db)

        cls.add_to_class(mgr_name, ExtendedNegotiableManager())

    return cls
开发者ID:suselrd,项目名称:django-negotiation,代码行数:101,代码来源:decorators.py


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