Ticket #10413: 10413_2.diff
File 10413_2.diff, 3.1 KB (added by , 16 years ago) |
---|
-
django/db/models/fields/related.py
332 332 333 333 def add(self, *objs): 334 334 for obj in objs: 335 if not isinstance(obj, self.model): 336 raise TypeError, "'%s' instance expected" % self.model._meta.object_name 335 337 setattr(obj, rel_field.name, instance) 336 338 obj.save() 337 339 add.alters_data = True … … 452 454 453 455 # If there aren't any objects, there is nothing to do. 454 456 if objs: 457 from django.db.models.base import Model 455 458 # Check that all the objects are of the right type 456 459 new_ids = set() 457 460 for obj in objs: 458 461 if isinstance(obj, self.model): 459 462 new_ids.add(obj._get_pk_val()) 463 elif isinstance(obj, Model): 464 raise TypeError, "'%s' instance expected" % self.model._meta.object_name 460 465 else: 461 466 new_ids.add(obj) 462 467 # Add the newly created or already existing objects to the join table. -
django/contrib/contenttypes/generic.py
253 253 254 254 def add(self, *objs): 255 255 for obj in objs: 256 if not isinstance(obj, self.model): 257 raise TypeError, "'%s' instance expected" % self.model._meta.object_name 256 258 setattr(obj, self.content_type_field_name, self.content_type) 257 259 setattr(obj, self.object_id_field_name, self.pk_val) 258 260 obj.save() -
tests/modeltests/many_to_many/models.py
61 61 # Adding a second time is OK 62 62 >>> a2.publications.add(p3) 63 63 64 # Adding an object of the wrong type raises TypeError 65 >>> a2.publications.add(a1) 66 Traceback (most recent call last): 67 ... 68 TypeError: 'Publication' instance expected 69 64 70 # Add a Publication directly via publications.add by using keyword arguments. 65 71 >>> new_publication = a2.publications.create(title='Highlights for Children') 66 72 -
tests/modeltests/many_to_one/models.py
72 72 >>> r2.article_set.add(new_article2) 73 73 >>> new_article2.reporter.id 74 74 2 75 76 # Adding an object of the wrong type raises TypeError 77 >>> r.article_set.add(r2) 78 Traceback (most recent call last): 79 ... 80 TypeError: 'Article' instance expected 81 75 82 >>> r.article_set.all() 76 83 [<Article: John's second story>, <Article: This is a test>] 77 84 >>> r2.article_set.all()