2010-08-12 58 views
0

這是我的代碼來獲得配方數據在編輯數據從inlineformset_factory丟失

objRecipe = models.Recipe.objects.get(id=recipe_id) 
recipe = models.RecipeForm(instance=objRecipe) 

objRecipeSteps = models.RecipeStep.objects.filter(recipe__id = objRecipe.id) 
recipeSteps = models.RecipeStepFormSet(queryset=objRecipeSteps) 

我能夠從「配方」而不是從「recipeSteps」顯示的數據。

這是我的模板代碼

{{ recipeSteps.management_form }} 

    {% for form in recipeSteps.forms %} 
     <div class="form-row"> 
     <span class="label"> 
      <span class="step-add"><a href="#">Add</a></span> 
      <span class="step-remove"><a href="#">Remove</a></span> 
     </span> 
     {{ form.recipe_step }} 
     </div> 
    {% endfor %} 

我找不到任何東西在這裏 http://docs.djangoproject.com/en/1.2/topics/forms/modelforms/#inline-formsets

回答

0

那麼,你的鏈接解釋怎樣做。而不是傳遞一個查詢集,傳遞instance參數,這是Recipe對象。

recipeSteps = models.RecipeStepFormSet(instance=objRecipe)