I want to show a model property in a template that uses inlineformset_factory. Is it possible? I have not seen a single example.
I am trying to display 'json_data' in my template
class RecipeIngredient(models.Model): recipe = models.ForeignKey(Recipe) ingredient = models.ForeignKey(Ingredient) serving_size = models.ForeignKey(ServingSize) quantity = models.IntegerField() order = models.IntegerField() created = models.DateTimeField(auto_now_add = True) updated = models.DateTimeField(auto_now = True) def _get_json_data(self): return u'%s %s' % (self.id, self.ingredient.name) json_data = property(_get_json_data)
in views.py
RecipeIngredientFormSet = inlineformset_factory(models.Recipe, models.RecipeIngredient, form=forms.RecipeIngredientForm, extra=0) recipeIngredients = RecipeIngredientFormSet(instance = objRecipe)
In my template, I have this, but I can’t see anything
{% for form in recipeIngredients %} {{ form.json_data }} {% endfor %}
django django-models
iJK
source share