On Thu, Mar 7, 2013 at 9:21 PM, Dilip M <dilip...@gmail.com> wrote:

> Hi,
>
> Here is what I am trying to do. Get the root folder name in form 1 and
> list the found sub directories (matching a pattern) and give an
> option for user to select the sub dirs. Once selected,  I want to save the
> model.
>
> 1. How to dynamically display found sub directories in form 2. I have
> defined a method (def _findSubs) in views.py
> 2. I have split a model into 2 forms. How to save the data fetched from 2
> forms into one model.
> 3. I have read the docs. But couldn't figure out where to put
> WizardView.get_form_initial() method. My knowledge with Django is very
> trivial.
>
> Here is what I am doing.
>
> --------------------
> models.py
> -------------------
>
> from django.db import models
>
> class Tree(models.Model):
>     rootDir = models.CharField(max_length=100) # will be populated using
> form 1
>     subDirs = models.CharField(max_length=100) # will be populated using
> form 2
>
>     def __unicode__(self):
>         return u'%s %s' % (self.rootDir, self.subDir)
>
> -------------------
> forms.py
> -------------------
>
> from django import forms
> from myapp.models import Tree
>
> class MainForm(forms.ModelForm):
>     class Meta:
>         model = Tree
>         exclude = ('subDirs')
>
> class SecondForm(forms.Form):
>     SUBDIRS = # _findSubs result should be here.
>     SELECTED =
> forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple, choices =
> SUBDIRS)
>
> --------------------
> views.py
> -------------------
>
> from django.shortcuts import render
> from django.http import HttpResponseRedirect
> from django.contrib.formtools.wizard.views import SessionWizardView
> from myapp.forms import MainForm, SecondForm
>
>
> FORMS = [("main", MainForm), ("select", SecondForm)]
> TEMPLATES = {"main": "main.html", "select": "select.html"}
>
> class FormWizard(SessionWizardView):
>
>     def get_template_names(self):
>         return [TEMPLATES[self.steps.current]]
>
>     def done(self, form_list, **kwargs):
>         # Now save Model here. HOW??
>         pass
>
>
> def main(request):
>
>     if request.method == 'POST':
>         http_req_type = request.method
>         mainform = MainForm(request.POST)
>
>         if mainform.is_valid():
>             cd = mainform.cleaned_data
>             tree = cd['rootDir']
>            subdirs = _findSubs(tree) # Assuming I get dir1, dir2 over here.
>


Want to pass the found 'subdirs' as a MultipleChoice options for
'SecondForm'





>     else:
>         http_req_type = request.method
>         mainform = MainForm()
>
>     return render(request, 'main.html', locals())
>
> def selection(request):
>     if request.method == 'POST':
>         http_req_type = request.method
>         selectionform = SecondForm(request.POST)
>
>         if selectionform.is_valid():
>             cd = selectionform.cleaned_data
>             subdirs = selectionform.cleaned_data.get('SELECTED')
>             return HttpResponseRedirect('/done/')
>     else:
>         http_req_type = request.method
>         form = SecondForm()
>
>     return render(request, 'select.html', {'form':form })
>
> def _findSubs(tree):
>     ''' Return a list of sub directory matching the pre-defined patter
>     '''
>     # some logic here. Don't worry abt it.
>     return subs
>
>
> -------------------
> urls.py
> -------------------
> from myapp import views
>
>     url(r'^main/', views.FormWizard.as_view(views.FORMS)),
>
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to