[Django] #29445: Compute defaults values with using of objects manager

6 views
Skip to first unread message

Django

unread,
May 25, 2018, 3:38:17 PM5/25/18
to django-...@googlegroups.com
#29445: Compute defaults values with using of objects manager
-------------------------------------+-------------------------------------
Reporter: Yurii | Owner: nobody
Shtrikker |
Type: New | Status: new
feature |
Component: | Version: 2.0
contrib.admin | Keywords: compute, defaults,
Severity: Normal | fields, admin site, form
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 1 |
-------------------------------------+-------------------------------------
Background:
I have an issue for add a field used for ordering records to few models .
Problem is pre-defined value, that should calculate as currently max value
plus ten. For example:
Add first record. Field should be a 10 by default.
Add second record. Field should be a 20 by default.
Add third record. Field should be a 30 by default, but we change it to 15
for placing between first two records.
Add fourth record. Field should be a 30 by default.

For implement this logic I need access to class object when default method
is called (I mean method specifying as value for default argument for
field).
But at method call I don't get any arguments. In case when I need
implement this field for single model - I can use model name as his
objects argument for this logic. But for many models I thinks it's will be
bad. Abstract model also not a choice, because it doesn't have a objects
manager.

So I remember about prepopulated fields in BaseModelAdmin (this all need
inly for admin site), and I use formfield_for_dbfield for implementing
this logic.

Now I want to ask about add new feature to add compute_defaults dict to
BaseModelAdmin. Key used as field name selector and value as computing
function (information about model and current field we can get from
db_field variable). I can create PL with this feature by myself, but
should I do it? Is it need to somebody else? And what you all thinking
about this idea?

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

Django

unread,
May 27, 2018, 7:04:28 PM5/27/18
to django-...@googlegroups.com
#29445: Compute defaults values with using of objects manager
-------------------------------------+-------------------------------------
Reporter: Yurii Shtrikker | Owner: nobody
Type: New feature | Status: closed
Component: contrib.admin | Version: 2.0
Severity: Normal | Resolution: wontfix
Keywords: compute, defaults, | Triage Stage:
fields, admin site, form | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: new => closed
* resolution: => wontfix


Comment:

The solution sounds rather specialized to me. I think the logic could be
implemented in a custom form. You might try asking for help using the
resources linked from TicketClosingReasons/UseSupportChannels.

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

Reply all
Reply to author
Forward
0 new messages