Sunday, January 13, 2019

Set default value in field dependant on another model?

We have two models: Resources and Quota

Resources model instances include:
- red things
- yellow things 
- blue things

Quota have two fields, one is a FK to a Resource, the other is "desired quota".
When instantiating the Quota request form, we create a form for each Resource.

I'd like to autofill the "desired quota" field on each form, but make it dependent on which Resource it is representing.

IE, when someone makes a resource request, we expect them to want

1 red thing
5 yellow things
10 blue things

Do some searching, there's a lot pointing to Signals, but I remember someone once saying "if you are using signals, you should re-write you logic" or somesuch, so I thought I'd ask here.

FWIW - and this is well beyond my control - we are on Django 1.8

Cheers
L.

--
------
"The fact that you're still saying something like 'feminism gone mad' suggests that feminism hasn't gone mad ENOUGH yet."

Helen Zaltzman / @HelenZaltzman
https://twitter.com/HelenZaltzman/status/1065384934846545920

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAGBeqiNqNz244qXHzvXPpqZQ8iS6iE82X5CO87kfZ4o7KGpPDQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment