My application is VERY low volume, so I just do this to KISS
(resident, created) = models.Resident.objects.get_or_create(pk=resid, defaults=r) resident.__dict__.update(r) resident.save() From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On Behalf Of Jonathan French Sent: Tuesday, June 12, 2012 7:52 AM To: django-users@googlegroups.com Subject: Re: DRY violation using get_or_create with defaults On 12 June 2012 04:44, Jerome Baum <jer...@jeromebaum.com> wrote: Drop the "defaults" kwarg to get_or_create as apparently you're not using it. Also drop the conditional on those set/save statements. Ah, I should have made clear that some of the fields in defaults are NOT NULL, so it's necessary to pass them in defaults. That's the problem, really. I did start off by just doing get_or_create, set fields, save, with no conditional, but then some of the fields I needed to set started becoming NOT NULL. I guess I'm probably going to have to create a custom manager or utility function. It's annoying since I use some other custom managers already, but oh well. Thanks for all your suggestions. - ojno -- 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. -- 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.