#25340: Allow use of expressions in Model.objects.create()
----------------------------------------------+--------------------
Reporter: tarkatronic | Owner: nobody
Type: New feature | Status: new
Component: Database layer (models, ORM) | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
I have a case where I need to assign a field value from the return of a
database function, but I do not want to set a default for the field.
Currently, the following will work:
{{{
#!python
from django.db.models.expressions import Func
from .models import MyModel
instance = MyModel.objects.create(
...
)
instance.code = Func(*my_args, function='generate_unique_code')
instance.save(update_fields=['code'])
}}}
However, the following:
{{{
#!python
from django.db.models.expressions import Func
from .models import MyModel
instance = MyModel.objects.create(
...,
code=Func(*my_args, function='generate_unique_code')
)
}}}
produces `TypeError: int() argument must be a string, a bytes-like object
or a number, not 'Func'`
I would expect that these two methods for assigning the value should
behave similarly.
--
Ticket URL: <https://code.djangoproject.com/ticket/25340>
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/054.723f21da27bd99a8661458b7641235c7%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.