Opened 6 years ago

Closed 6 years ago

#29445 closed New feature (wontfix)

Compute defaults values with using of objects manager

Reported by: Yurii Shtrikker Owned by: nobody
Component: contrib.admin Version: 2.0
Severity: Normal Keywords: compute, defaults, fields, admin site, form
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: yes

Description

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?

Change History (1)

comment:1 by Tim Graham, 6 years ago

Resolution: wontfix
Status: newclosed

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.

Note: See TracTickets for help on using tickets.
Back to Top