#29148: Explain how to use QuerySet.get_or_create() with Q objects
-------------------------------+------------------------------------
Reporter: Mike Lissner | Owner: nobody
Type: New feature | Status: new
Component: Documentation | Version: 2.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by Tim Graham):
* stage: Unreviewed => Accepted
Old description:
> This technique is useful if you want to use Q objects in conjunction with
> the get or create method, and it's documented in a few places around the
> web.
>
> I brought this up in the forums yesterday and somebody suggested that it
> be documented:
>
> https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg
> /django-developers/e3sJ6OiHEd0/Yrg-Z9uRAgAJ
>
> I gave this a try, but I don't understand the documentation system and I
> sadly don't have time to figure it out. Seems though like a change could
> go here:
>
> https://github.com/django/django/blob/master/docs/ref/models/querysets.txt#L1886
>
> I think something along the lines of:
>
> > get_or_create() can be used with Q objects by chaining them together
> like so:
>
> > An example
>
> > When this is done, the logic performs as above, but matches are made
> according to the query in the Q object.
>
> I imagine this also works for update_or_create, but I'm not sure how to
> document that too. Maybe just a quick mention:
>
> > update_or_create() can be used with Q objects using the same technique
> as documented above for get_or_create()
New description:
This technique is useful if you want to use Q objects in conjunction with
the get or create method, and it's documented in a few places around the
web.
I brought this up in the forums yesterday and somebody suggested that it
be documented:
https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg
/django-developers/e3sJ6OiHEd0/Yrg-Z9uRAgAJ
I gave this a try, but I don't understand the documentation system and I
sadly don't have time to figure it out. Seems though like a change could
go here:
https://github.com/django/django/blob/master/docs/ref/models/querysets.txt#L1886
I think something along the lines of:
> get_or_create() can be used with Q objects by chaining them together
like so:
>
> An example
>
> When this is done, the logic performs as above, but matches are made
according to the query in the Q object.
I imagine this also works for update_or_create, but I'm not sure how to
document that too. Maybe just a quick mention:
> update_or_create() can be used with Q objects using the same technique
as documented above for get_or_create()
--
--
Ticket URL: <https://code.djangoproject.com/ticket/29148#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/066.5f305a768f8b900a620b5679d1abdbed%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.