I'm working on a program to keep track of recipes. Thus I have two main
tables, a recipe table and an ingredients table. They look roughly like
this: (some code taken out for conciseness)

class Recipe(models.Model):
        recipe_name = models.CharField(maxlength=100)
        directions = models.TextField(core=True)
        date_added = models.DateTimeField(auto_now_add=True)
        last_modified = models.DateTimeField(auto_now=True)
        category = models.ManyToManyField(Category)

class Ingredient(models.Model):
        recipe = models.ForeignKey(Recipe, edit_inline=models.TABULAR,
num_in_admin=10)
        ingredient = models.CharField(maxlength=142, core=True)

I'm using the Admin on Recipe and in the admin interface it works fine
except that I can't put the ingredients above the directions. So I'm
working on creating my own add recipe form... To that end, I'm using
the following view:
def create_recipe(request):
        recipe_manipulator = Recipe.AddManipulator()

        if request.method == 'POST':
                new_recipe_data = request.POST.copy()
                recipe_errors =
recipe_manipulator.get_validation_errors(new_recipe_data)
                if not recipe_errors:
                        # No errors, save the data

recipe_manipulator.do_html2python(new_recipe_data)
                        new_recipe =
recipe_manipulator.save(new_recipe_data)

                        # Redirect to the object's edit page.
                        return HttpResponseRedirect("/recipes/edit/%i/"
% new_recipe.id)
        else:
                # No POST, so we want a brand new form with no data or
errors
                recipe_errors = new_recipe_data = {}
        # Create the FormWrapper, template, context, response.
        recipe_form = forms.FormWrapper(recipe_manipulator,
new_recipe_data, recipe_errors)
        return render_to_response('recipes/create_form.html',
{'recipe_form':recipe_form })

and this template:
{% extends "base.html" %}

{% block content %}
<h1>Insert a new Recipe:</h1>

{% if recipe_form.has_errors %}
<h2>Please correct the following error{{
recipe_form.error_dict|pluralize }}:</h2>
{% endif %}

<form method="post" action=".">
<p>
    <label for="id_name">Recipe Title:</label> {{
recipe_form.recipe_name }}
    {% if recipe_form.recipe_name.errors %}*** {{
recipe_form.recipe_name.errors|join:", " }}{% endif %}
</p>
<p>
    <label for="id_category">Category:</label> {{ recipe_form.category
}}
    {% if recipe_form.category.errors %}*** {{
recipe_form.category.errors|join:", " }}{% endif %}
</p>
[...]
<p>
    <label for="id_ingredient">Ingredient:</label> {{
recipe_form.ingredient }}
    {% if recipe_form.ingredient.errors %}*** {{
recipe_form.ingredient.errors|join:", " }}{% endif %}
</p>
<p>
    <label for="id_directions">Directions:</label> {{
recipe_form.directions }}
    {% if recipe_form.directions.errors %}*** {{
recipe_form.directions.errors|join:", " }}{% endif %}
</p>
<input type="submit" value="Add Recipe" />
</form>
{% endblock %}

Only my recipe_form.ingredient doesn't work. (Not that I really
expected it to) How can I insert the 10 ingredient fields in the same
way that the admin console does?


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to