Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6829675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:31:41+00:00 2026-05-26T22:31:41+00:00

I’ve seen this post and it’s not working (in part because it’s dated). I’ve

  • 0

I’ve seen this post and it’s not working (in part because it’s dated). I’ve also studied the source tree to no avail (the tests helped) but I can’t find my answer. What I’m looking to do is get a seed set of data in form0 (‘start’) which will dynamically build a formset for step2. Step 2 is simply a verification step.

  1. ‘start’ – User enters subdivision (subA), zipcode (12345) and a csv of lots (51,52,53)
  2. ‘step2’ – A dynamic form (modelformset) is created with 3 forms representing 51,52,53
  3. User hits go and the models are built

i.e.

data = [ { 'subdivision': <subA>, 'zipcode': '12345', 'lot_number': '51'}
         { 'subdivision': <subA>, 'zipcode': '12345', 'lot_number': '52'}
         { 'subdivision': <subA>, 'zipcode': '12345', 'lot_number': '53'} ]

What I’ve tried

When implementing the solution here I only get data=None. This is dated and looking through the source I thought the “right” way to do this was to simply override the get_form_instance method and feed itget_cleaned_data_for_step, but that appears to revalidate and do a lot more stuff than what I think it needs to (and it didn’t work).

So.. What I’m looking for is two things.

  1. What is the right way to get the previous forms data.
  2. How do I take that data and use it to create a n-number of formsets.

FWIW I am using Django 1.4-alpha formset wizard.

Here is what I have.

# urls.py
    url(r'homes/bulk/$', TestWizard.as_view([('start', BulkHomeForm0),
                                             ('step2', HomeFormSet)])),

# Models.py
class Subdivision(models.Model):
    name = models.CharField(max_length=64)

class Home(models.Model):
    lot_number = models.CharField(max_length=16)
    subdivision = models.ForeignKey(Subdivision)
    zipcode = models.IntegerField(validators=[validate_zipcode], null=True)

# Forms
class BulkHomeForm0(forms.Form):
    subdivision = forms.ModelChoiceField(queryset=Subdivision.objects.all(), required=True)
    zipcode = USZipCodeField(required=True)
    lots = forms.CharField(max_length=5000, widget=forms.Textarea()

    def clean(self):
        subdivision = self.cleaned_data.get('subdivision', False)
        zipcode = self.cleaned_data.get('zipcode', False)
        final_data = []
        for item in self.cleaned_data.get('lots', "").split(",")
            final_data.append({'subdivision':subdivision, 
                               'zipcode':zipcode, 
                               'lot_number':item})
        self.cleaned_data['homes'] = final_data

class BulkHomeForm1(forms.ModelForm):
    class Meta:
        model = Home

HomeFormSet = modelformset_factory(Home, form=BulkHomeForm1, extra=2)

# Views.py
class TestWizard(WizardView):
    storage_name = 'django.contrib.formtools.wizard.storage.session.SessionStorage'

    def get_form(self, step=None, data=None, files=None):
        form = super(TestWizard, self).get_form(step=step, data=data, files=files)
        return form

    def done(self, form_list, **kwargs):
        return render_to_response('done.html', {
            'form_data': [form.cleaned_data for form in form_list],
        })
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:31:42+00:00Added an answer on May 26, 2026 at 10:31 pm

    Here is what I came up with..

    I couldn’t seem to get a modelForm to work nicely so I kept the two separate and merged them at done. It isn’t perfect yet but it’s getting close..

    class BulkHomeForm1(forms.Form):
    
        lot_number = forms.CharField(max_length=16, required=True)
        street_line1 = forms.CharField(max_length=100, required=True)
        floorplan = forms.ModelChoiceField(queryset=Floorplan.objects.filter(is_active=True), required=False)
        start_date = forms.DateField(required=False)
    
    temp_storage_location = tempfile.mkdtemp(dir=settings.MEDIA_ROOT, prefix="bulk_homes_")
    os.chmod(temp_storage_location,  02775) # TODO FIX ME
    temp_storage = FileSystemStorage(location=temp_storage_location)
    
    class BulkHomeWizard(SessionWizardView):
        file_storage = temp_storage
    
        def get_form(self, step=None, data=None, files=None):
    
            form = super(BulkHomeWizard, self).get_form(step=step, data=data, files=files)
            if self.steps.current == 'start' and form.prefix != "step2":
                # Limit the subdivisions down to the specifics
                sub_qs = Subdivision.objects.filter(is_active=True)
                if self.request.user.company_type == "rater":
                    sub_qs = sub_qs.filter(rater_orgs=self.request.user.company.id)
                elif self.request.user.company_type == "eep":
                    sub_qs = sub_qs.filter(eep_orgs=self.request.user.company.id)
                form.fields['subdivision'].queryset = sub_qs
            return form
    
        def get_context_data(self, form, **kwargs):
            context = super(BulkHomeWizard, self).get_context_data(form, **kwargs)
            self.template_name = 'axis/bulk_%s.html' %  self.steps.current
            return context
    
        def get_form_initial(self, step):
            """This is used to seed the model set with information from the previous step"""
            if step == 'step2':
                log.info("Into Step 2")
                data = self.get_cleaned_data_for_step('start')['homes']
                return data
            return self.initial_dict.get(step, {})
    
        def done(self, form_list, **kwargs):
    
            cleaned_data = [form.cleaned_data for form in form_list]
    
            subdivision = cleaned_data[0].get('subdivision')
            city = subdivision.city
            state = subdivision.state
            zipcode = cleaned_data[0].get('zipcode')
    
            for form in cleaned_data[1]:
                data = Home.objects.get_or_create(lot_number = form.get('lot_number'),
                                                  floorplan = form.get('floorplan', None),
                                                  street_line1 = form.get('street_line1', None),
                                                  subdivision = subdivision,
                                                  city = subdivision.city, state=subdivision.state,
                                                  zipcode=zipcode,
                                                  start_date = form.get('start_date', None),)
                obj, created = data
                obj.clean()
                obj.save()
                if created:
                    log.info("Create new Home")
    
            return HttpResponseRedirect(reverse("subdivision_view", kwargs={'subdivision_id': subdivision.id}))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.