Monday, 19 August 2013

How to access and make use of html data in django?

How to access and make use of html data in django?

I am having a hard time figuring out the right logic for my problem, i
have 3 models,
class Item(SmartModel):
name= models.CharField(max_length=64,help_text="Name for this item e.g
Hamburger")
price=models.DecimalField(max_digits=9,decimal_places=2)
optionalitems =
models.ManyToManyField('optionalitems.OptionalItemCategory',null=True,blank=True)
class OptionalItems(SmartModel):
"""Optional items that belong to an item e.g topping that belongs to
a pizza"""
name = models.CharField(max_length=20, help_text="Item name.")
price = models.DecimalField(max_digits=9, decimal_places=2,
null=True,blank=True)
class OptionalItemCategory(SmartModel):
"""Category to which optional items belong"""
title = models.CharField(max_length=20,help_text="Category name")
optional_items = models.ManyToManyField(OptionalItems)
in my template,
{%for optionalcategory in optionalcategories %}
<h5 id="blah"> </h5>
{% for optionalitem in optionalcategory.optional_items.all %}
<ul>
<input type="radio" value="radio" name="optional" value="op"><li
id="item_appearence"></span></li><a/>
</ul>
{% endfor %}
{% endfor %}
So for example an Item like a burrito will have an OptionalItem steak or
chicken.I am able to access the Item like so item =
get_object_or_404(Item, pk=obj.id) but my problem is i cannot figure out
how to capture the OptionalItem. I want to be able to access the
OptionalItem steak and its other fields like price

No comments:

Post a Comment