Re: Django - PrePopulate the Foreign Key on the web page, and use that id to save the model.

2020-04-13 Thread Antje Kazimiers
you're welcome, Mayank! Adding initial to your ModelChoiceField definition should give you the preselection. self.fields['project'] = forms.ModelChoiceField( initial=projectid, queryset=Project.objects.filter(id=projectid) ) On Sun, Apr 12, 2020 at

Re: Django - PrePopulate the Foreign Key on the web page, and use that id to save the model.

2020-04-12 Thread _M_A_Y_A_N_K_
Cool, thanks Antje. Seems it is working now, the only thing is in Drop-down i will have the Project Name for which the URL is rest of the PRojects are removed from drop down. Now will work to have pre-selected. As of now it will default display as -- with only one required project name.

Re: Django - PrePopulate the Foreign Key on the web page, and use that id to save the model.

2020-04-12 Thread Antje Kazimiers
Hi, I think in your view modulesView() you need to pass the project id to ModuleForm: .. else : form = ModuleForm(projectid) .. and then you need to overwrite the constructor of ModuleForm by adding an __init__ function: def __init__(self, projectid=None, *args, **kwargs):

Django - PrePopulate the Foreign Key on the web page, and use that id to save the model.

2020-04-12 Thread Mayank Tripathi
Hi All, I am facing an issue, to pre-populate the Foreign Key on the web page. Actually i have two models Projects and Modules. To create a Module, one has to select the Project and go to Module page for create it, but there the Project is not populated. Below are the details... Please guide