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: [email protected]
[mailto:[email protected]] On Behalf Of Jonathan French
Sent: Tuesday, June 12, 2012 7:52 AM
To: [email protected]
Subject: Re: DRY violation using get_or_create with defaults
On 12 June 2012 04:44, Jerome Baum <[email protected]> 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 [email protected].
To unsubscribe from this group, send email to
[email protected].
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.