Thanks Tom. But with this approach - > foo = Foo.objects.get(pk=foo_id) > foo.field = new_value > foo.save()
There is an extra DB call, first the the data, and then another one to save it. If you have the primary_key with you, only one should suffice. I mean, when we step back and look at the whole scenario, there are thousand consumers doing this, and each has one extra DB call. That's pretty expensive. On Sep 22, 11:41 am, Tom Evans <tevans...@googlemail.com> wrote: > On Tue, 2009-09-22 at 08:13 -0700, PlanetUnknown wrote: > > I'm sure I'm missing something simple here, since its a common flow - > > > 1.) e.g. model Person - has 4 fields - > > person_id = models.AutoField(primary_key=True) > > person_name = models.CharField(max_length=50) > > comments = models.TextField(blank=True) > > create_dt = models.DateTimeField(auto_now_add=True) > > modify_dt = models.DateTimeField(auto_now_add=True) > > class Meta: > > unique_together = ("person_id", "person_name") > > > 2.) When I save a new person, everything works normal, since I'm > > giving - > > p1 = Person(person_id=None, person_name=personNameArg, > > comments=pComment) > > > 3.) After this save is performed, I have the "person_id" of this > > person. When someone hits save again, I do this - > > > p1 = Person(person_id=personIdArg, person_name=personNameArg, > > comments=pComment) > > where personIdArg is the earlier saved id. > > > I get the error - "create_dt cannot be Null", I see that dJango is > > correctly trying to update, but since I didn't pass create_dt, it is > > setting it to NULL in the update query. > > > I just want it to be left alone, since it already has a value. Is > > there a way to tell django to not touch these fields ? > > > Thanks! > > It isn't that common; I haven't got that in any of my views. > > The canonical way to update an item, AFAICT, is like so: > > foo = Foo.objects.get(pk=foo_id) > foo.field = new_value > foo.save() > > Cheers > > Tom --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---