[Django] #33478: Change get_or_create input parameters

5 views
Skip to first unread message

Django

unread,
Jan 31, 2022, 10:10:13 AM1/31/22
to django-...@googlegroups.com
#33478: Change get_or_create input parameters
------------------------------------------------+------------------------
Reporter: MojixCoder | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Uncategorized | Version: 4.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
currently in Django we have `get_or_create(defaults=None, **kwargs)`,
which works fine.
But what if our model has a field called `defaults`.
Then how can we query by that field.
Maybe we should change `defaults` to `_defaults`?

--
Ticket URL: <https://code.djangoproject.com/ticket/33478>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 31, 2022, 11:05:49 AM1/31/22
to django-...@googlegroups.com
#33478: Can't use QuerySet.get_or_create() with a field named defaults
-------------------------------------+-------------------------------------
Reporter: MojixCoder | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Database layer | Version: 4.0
(models, ORM) |
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: new => closed
* resolution: => invalid
* component: Uncategorized => Database layer (models, ORM)


Comment:

From the `get_or_create()` docs:

> If you have a field named `defaults` and want to use it as an exact
lookup in `get_or_create()`, just use `'defaults__exact'`, like so:
> {{{#!python
> Foo.objects.get_or_create(defaults__exact='bar', defaults={'defaults':
'baz'})
> }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33478#comment:1>

Reply all
Reply to author
Forward
0 new messages