On Sun, 2009-03-15 at 23:11 -0500, Gary Wilson Jr. wrote: > On Sun, Mar 15, 2009 at 4:40 PM, Malcolm Tredinnick > <malc...@pointy-stick.com> wrote: > > On Sun, 2009-03-15 at 12:12 -0500, Gary Wilson Jr. wrote: > >> Another option would be to allow Model.update() to take the > >> force_update and force_insert parameters that save() does and just > >> pass these through to the save() call. > > > > Aside from the fact that I dislike the ideal as a whole (see below), if > > you're going to have a method called update(), it should do what it says > > on the box. It's not called maybe_create_maybe_update() -- we already > > have that method (it's spelled "save()"). > > This is the way I lean too, having update() use > save(force_update=True). We already have Model.__init__ and > Manager.create() for creation. > > >> What do you think? > > > > I'm very unconvinced that the idea in the ticket is worth it. It's a > > two-liner if somebody wants to do this in their code, so whilst we *can* > > add this method, adding yet another thing to Model namespace that also > > adds to the documentation and things that need to be tested, etc, > > doesn't seem worth it to me. We already have save(force_update=True) to > > do an update. Adding the extra line to also populate some model fields > > doesn't seem like a great API addition that we can't live without to me. > > Sure, the model update() method is a convenience that we can live > without, but I would argue that it rounds out CRUD for models and > makes things a bit more readable: > > obj.update(field1=value1, field2=value2)
So let me predict the obvious future here: (1) "Can we also have an insert() method?" times about 5 times over the next 12 months. (2) "When do I use update? What is the difference between update and save(force_update)?" times any number of times on django-users. (3) "The documentation is unclear / has formatting errors / whatever" (more work required). I think it adds multiple choices when one already exists. I use force_update=True a fair bit and I don't see this actually making code easier, since that type of pattern doesn't seem to come up that much. My models are populated a bit more incrementally (and the loop just isn't hard). For people who do use this pattern a lot, I'm already on record on this list encouraging them to add update() and insert() to their model classes if they want. > With Model.update() and Manager.update_or_create(), we are saving two > to five lines of code for operations that are fairly common. "Fairly common" is hard to quantify. We're guessing pretty blindly here. I'm assuming you use the pattern a bit; as I've noted, I do not. I'm at most -0 on both options. Malcolm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~----------~----~----~----~------~----~------~--~---