﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
34280	Support create defaults for update_or_create	Tim Schilling	Tim Schilling	"I proposed the idea of extending `update_or_create` to support specifying a different set of defaults for the create operation on the [forum](https://forum.djangoproject.com/t/feature-idea-update-or-create-to-allow-different-defaults-for-create-and-update-operations/18300/15). There seems to be consensus it's a positive add to Django.

Adam raised concerns with my proposed approach of adding a `create_defaults` parameter to the function since this would conflict with any fields on a model named, `create_defaults`. Jeff did a code search on github for that term and didn't find any matches. I suspect if someone where using a field named `create_defaults`, it would be a JSON or object type field. Those don't seem like reasonable candidates to be part of a `UniqueConstraint`, which should be underlying the look-up arguments to `update_or_create`.

I do like the idea of having a separate parameter for `create_defaults`, but if we must preserve 100% backwards compatibility, Adam's suggestion of having defaults be set to another object makes the most sense.

My blocking question is, which approach should I take?

From the forum post:

    I’ve run into a use-case in which it’d be helpful to have the ability to specify a different set of defaults for the update operation compared to the create operation. While I don’t expect my particular use case to translate, here’s a more generic one.
    Given the following Record model:
    {{{
    class Record(models.Model):
        some_id = models.CharField(unique=True)
        created_by = models.ForeignKey(User, ...)
        modified_by = models.ForeignKey(User, null=True, blank=True, ...)
    }}}
    When a record is created, we would want to set created_by, but if it’s being updated, we’d want to set modified_by. This use case can’t be solved by using update_or_create, unless it allows for us to specify a different set of default values.
    {{{
    Record.objects.update_or_create(
        some_id=some_value,
        defaults={""modified_by"": user},
        create_defaults={""created_by"": user},
    )
    }}}
"	New feature	closed	Database layer (models, ORM)	dev	Normal	fixed			Ready for checkin	1	0	0	0	0	0
