Ticket #8669: create-always-inserts.diff

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

Fixes for 3 different create() methods

  • db/models/fields/related.py

     
    294294            def get_query_set(self):
    295295                return superclass.get_query_set(self).filter(**(self.core_filters))
    296296
    297             def add(self, *objs):
     297            def add(self, *objs, force_insert=False, force_update=False):
    298298                for obj in objs:
    299299                    setattr(obj, rel_field.name, instance)
    300                     obj.save()
     300                    obj.save(force_insert=force_insert, force_update=force_update)
    301301            add.alters_data = True
    302302
    303303            def create(self, **kwargs):
    304304                new_obj = self.model(**kwargs)
    305                 self.add(new_obj)
     305                self.add(new_obj, force_insert=True)
    306306                return new_obj
    307307            create.alters_data = True
    308308
     
    406406            if through is not None:
    407407                raise AttributeError, "Cannot use create() on a ManyToManyField which specifies an intermediary model. Use %s's Manager instead." % through
    408408            new_obj = self.model(**kwargs)
    409             new_obj.save()
     409            new_obj.save(force_insert=True)
    410410            self.add(new_obj)
    411411            return new_obj
    412412        create.alters_data = True
  • contrib/contenttypes/generic.py

     
    273273            kwargs[self.content_type_field_name] = self.content_type
    274274            kwargs[self.object_id_field_name] = self.pk_val
    275275            obj = self.model(**kwargs)
    276             obj.save()
     276            obj.save(force_insert=True)
    277277            return obj
    278278        create.alters_data = True
    279279
Back to Top