public
Last active

  • Download Gist
gistfile1.diff
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py
index 8024981..bcaee9c 100644
--- a/django/db/models/fields/related.py
+++ b/django/db/models/fields/related.py
@@ -441,7 +441,7 @@ class ForeignRelatedObjectsDescriptor(object):
def create(self, **kwargs):
kwargs[rel_field.name] = self.instance
db = router.db_for_write(self.model, instance=self.instance)
- return super(RelatedManager, self.db_manager(db)).create(**kwargs)
+ return self.db_manager(db).get_queryset().create(**kwargs)
create.alters_data = True
def get_or_create(self, **kwargs):
@@ -449,7 +449,7 @@ class ForeignRelatedObjectsDescriptor(object):
# ForeignRelatedObjectsDescriptor knows about.
kwargs[rel_field.name] = self.instance
db = router.db_for_write(self.model, instance=self.instance)
- return super(RelatedManager, self.db_manager(db)).get_or_create(**kwargs)
+ return self.db_manager(db).get_queryset().get_or_create(**kwargs)
get_or_create.alters_data = True
# remove() and clear() are only provided if the ForeignKey can have a value of null.
@@ -593,15 +593,14 @@ def create_many_related_manager(superclass, rel):
opts = self.through._meta
raise AttributeError("Cannot use create() on a ManyToManyField which specifies an intermediary model. Use %s.%s's Manager instead." % (opts.app_label, opts.object_name))
db = router.db_for_write(self.instance.__class__, instance=self.instance)
- new_obj = super(ManyRelatedManager, self.db_manager(db)).create(**kwargs)
+ new_obj = self.db_manager(db).get_queryset().create(**kwargs)
self.add(new_obj)
return new_obj
create.alters_data = True
def get_or_create(self, **kwargs):
db = router.db_for_write(self.instance.__class__, instance=self.instance)
- obj, created = \
- super(ManyRelatedManager, self.db_manager(db)).get_or_create(**kwargs)
+ obj, created = self.db_manager(db).get_queryset().get_or_create(**kwargs)
# We only need to add() if created because if we got an object back
# from get() then the relationship already exists.
if created:
diff --git a/django/db/models/manager.py b/django/db/models/manager.py
index 457fc22..5009a26 100644
--- a/django/db/models/manager.py
+++ b/django/db/models/manager.py
@@ -136,12 +136,6 @@ class Manager(six.with_metaclass(RenameManagerMethods)):
def all(self):
return self.get_queryset()
- def get_or_create(self, **kwargs):
- return self.get_queryset().get_or_create(**kwargs)
-
- def create(self, **kwargs):
- return self.get_queryset().create(**kwargs)
-
def _insert(self, objs, fields, **kwargs):
return insert_query(self.model, objs, fields, **kwargs)
diff --git a/tests/multiple_database/models.py b/tests/multiple_database/models.py
index e464386..2058a81 100644
--- a/tests/multiple_database/models.py
+++ b/tests/multiple_database/models.py
@@ -42,11 +42,11 @@ class Person(models.Model):
class BookManager(models.Manager):
def create(self, *args, **kwargs):
kwargs.pop('extra_arg', None)
- return super(BookManager, self).create(*args, **kwargs)
+ return self.get_queryset().create(*args, **kwargs)
def get_or_create(self, *args, **kwargs):
kwargs.pop('extra_arg', None)
- return super(BookManager, self).get_or_create(*args, **kwargs)
+ return self.get_queryset().get_or_create(*args, **kwargs)
@python_2_unicode_compatible
class Book(models.Model):

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.