Note that there are some explanatory texts on larger screens.

plurals
  1. POdjango - dynamic select fields in forms
    text
    copied!<p>I have a model called picks that allows users to select an nfl team (from a static list). Whenever they choose a team, they can no longer choose that team again, so there selection choices are reduced by any teams they have chosen.<br> I have a function that I call in my view that figures out what teams they have not selected yet, but I cannot figure out how to pass this information to the form. I've looked at many form examples online but have not really found one that shows how to accomplish this. From what I've read, it seems like I should be calling this function from the forms.py file, but the function needs the user id and league id passed in as parameters so I'd rather just do it in the model. Can someone explain, or point me to an explanation showing how to pass in select field choices from a model to a form?</p> <p>I'm relatively new in both Django and Python so please excuse any obvious oversights I'm making here.</p> <p>Thanks!</p> <p><strong>EDIT</strong></p> <p>Ok, I think perhaps I gave too much non-crucial information for the issue here, I'll try to simplify the question here:</p> <p>I have a view which creates a form. The form has a select box in it. I calculate the options that should go in the select box inside of the view, based on the current user and a variable in the URL that launched the view. I would like to know how to pass the select options into the form, or if that is not how this should be accomplished. </p> <p>I don't have the code in front of me at this time to post, but I really don't think it's relevant to the problem. I hope I have made it generic enough.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload