Ticket #12351: t12351-r11807.diff

File t12351-r11807.diff, 1.2 KB (added by Fred Bartle, 15 years ago)

Override get() and get_or_create() behavior to GenericRelatedObjectManager

  • django/contrib/contenttypes/generic.py

     
    268268                obj.delete()
    269269        clear.alters_data = True
    270270
     271        def get(self, **kwargs):
     272            kwargs[self.content_type_field_name] = self.content_type
     273            kwargs[self.object_id_field_name] = self.pk_val
     274            return super(GenericRelatedObjectManager, self).get(**kwargs)
     275
    271276        def create(self, **kwargs):
    272277            kwargs[self.content_type_field_name] = self.content_type
    273278            kwargs[self.object_id_field_name] = self.pk_val
    274279            return super(GenericRelatedObjectManager, self).create(**kwargs)
    275280        create.alters_data = True
    276281
     282        def get_or_create(self, **kwargs):
     283            kwargs[self.content_type_field_name] = self.content_type
     284            kwargs[self.object_id_field_name] = self.pk_val
     285            return super(GenericRelatedObjectManager, self).get_or_create(**kwargs)
     286        get_or_create.alters_data = True
     287
    277288    return GenericRelatedObjectManager
    278289
    279290class GenericRel(ManyToManyRel):
Back to Top