I show two separate example projects. The first is contact-related and shows how to use the formwizard. The second is the ingredients for a recipe project that shows how to use inline strings in a form. I want inline strings in my formwizard just as they work in normal form.
I have a multi-format formwizard form. It is based on an example here . I modified it a bit to use the model.
models.py
from django.db import models
forms.py
class ContactForm1(forms.ModelForm): class Meta: model = Contact class ContactForm2(forms.ModelForm): class Meta: model = Contact2 class ContactWizard(FormWizard): @property def __name__(self): return self.__class__.__name__ def done(self, request, form_list):
urls.py
(r'^contact/$', ContactWizard([ContactForm1, ContactForm2])),
Separately, I have lines embedded in another form. I do this through inlineformset_factory in my opinion. This is not related to the above form example. . This is an example of recipe ingredients. I do it like:
views.py
def add(request): IngredientFormSet = inlineformset_factory(Recipe, Ingredient, fk_name="recipe", formfield_callback=curry(ingredient_form_callback, None)) if request.method == 'POST': form = RecipeForm(request.POST) formset = IngredientFormSet(request.POST) if form.is_valid() and formset.is_valid(): recipe = form.save() formset = IngredientFormSet(request.POST, instance=recipe) formset.save() return redirect("/edit/%s" % recipe.id) else: form = RecipeForm() formset = IngredientFormSet() return render_to_response("recipes_add.html", {"form":form, "formsets":formset}, context_instance=RequestContext(request))
recipes_add.html
<form method="post"> {% csrf_token %} <table> {{ form }} </table> <hr> <h3>Ingredients</h3> <div class="inline-group"> <div class="tabular inline-related last-related"> {{ formsets.management_form }} {% for formset in formsets.forms %} <table> {{ formset }} </table> {% endfor %} </div> </div> <p class="success tools"><a href="#" class="add">Add another row</a></p> <input type="submit" value="Add"> </form>
How can I make inline lines work in my multi-line formwizard form? models.py now looks like this because I want books to be embedded in contact . I want the lines to be in the first step of my viewfinder. Then go to step 2 and finish.
from django.db import models