本文整理汇总了Python中django.contrib.contenttypes.generic.GenericRelation类的典型用法代码示例。如果您正苦于以下问题:Python GenericRelation类的具体用法?Python GenericRelation怎么用?Python GenericRelation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GenericRelation类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post_through_setup
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")
示例2: contribute_to_class
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")
示例3: post_through_setup
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")
示例4: post_through_setup
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())
示例5: post_through_setup
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')
示例6: post_through_setup
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.')
示例7: post_through_setup
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.')
示例8: negotiable
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