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")
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, "tagged_items")
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")
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")
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())
def post_through_setup(self, cls): self.use_gfk = ( self.through is None ) self.rel.to = self.through._meta.get_field("group").rel.to if RelatedObject is not None: self.related = RelatedObject(self.through, cls, self) if self.use_gfk: groups = GenericRelation(self.through) groups.contribute_to_class(cls, "groups")
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')
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.')
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.')
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