[Answer]-Initial values in django forms

0👍

hmmm i got it working,Let me answer my own question,..here is the code …

    def get_form_initial(self,step):

    if 'project_id' in self.kwargs:
        project_id=self.kwargs['project_id']
        article=Marticles.objects.get(id=project_id)
        project_dict = model_to_dict(article)
        return project_dict
    else:
        return self.initial_dict.get(step,{})

I think this will be helpfull for you guyzz…

👤Friend

1👍

You can implement WizardView.get_form_initial(step) method to provide initial data for each step of the wizard.

Something like:

class FarticlesWizard(SessionWizardView):
    def get_form_initial(self, step):
        init_dict = {}
        #get object to populate data
        if step == '1':
            init_dict = { 'heading': obj.heading, 'content' : obj.content }
        if step == '2':
            init_dict = { 'country': obj.country, 'work' : obj.work }

        return init_dict

I’m not sure how would you get project_id in this method from url to query the object.

👤Rohan

Leave a comment