Last active
December 18, 2015 23:29
-
-
Save loic/5861660 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment