Ticket #8669: create-always-inserts.v3.diff

File create-always-inserts.v3.diff, 1.9 KB (added by Richard Davies <richard.davies@…>, 16 years ago)

Fix test suite failures (was a silly one line error in last patch)

  • django/db/models/fields/related.py

     
    301301            add.alters_data = True
    302302
    303303            def create(self, **kwargs):
    304                 new_obj = self.model(**kwargs)
    305                 self.add(new_obj)
    306                 return new_obj
     304                # Update kwargs with the related object that this
     305                # ForeignRelatedObjectsDescriptor knows about.
     306                kwargs.update({rel_field.name: instance})
     307                return super(RelatedManager, self).create(**kwargs)
    307308            create.alters_data = True
    308309
    309310            def get_or_create(self, **kwargs):
     
    405406            # from the method lookup table, as we do with add and remove.
    406407            if through is not None:
    407408                raise AttributeError, "Cannot use create() on a ManyToManyField which specifies an intermediary model. Use %s's Manager instead." % through
    408             new_obj = self.model(**kwargs)
    409             new_obj.save()
     409            new_obj = super(ManyRelatedManager, self).create(**kwargs)
    410410            self.add(new_obj)
    411411            return new_obj
    412412        create.alters_data = True
  • django/contrib/contenttypes/generic.py

     
    272272        def create(self, **kwargs):
    273273            kwargs[self.content_type_field_name] = self.content_type
    274274            kwargs[self.object_id_field_name] = self.pk_val
    275             obj = self.model(**kwargs)
    276             obj.save()
    277             return obj
     275            return super(GenericRelatedObjectManager, self).create(**kwargs)
    278276        create.alters_data = True
    279277
    280278    return GenericRelatedObjectManager
Back to Top