List of Django Dictionary Objects - Creating Templates

1

I'm trying to learn something about Django, and a question has come to me.

I have a dictionary with multiple keys and values. The idea is for each key to display a list of values with checkboxes that can be selected to perform other tasks later.

But I do not understand how I can create templates and then correlate keys with values using checkboxes in Django, could anyone give me a light?

    
asked by anonymous 12.08.2014 / 21:34

1 answer

1

Would not that be the idea?

model.py

class BookModel(models.Model):
  title=models.CharField()

class User(models.Model):
  username=models.CharField()

class Recommend(models.Model):
  user=models.ForeignKey(User)
  book=models.ForeignKey(BookModel)
  friends=models.ManyToManyField(User, related_name="recommended")

template.html

{% for friend in friends %}

<input type="checkbox" name="recommendations" id="option{{friend.id}}" value={{friend.username}} />
<label for="option{{friend.id}}"><b>{{friend.username}}</b></label><br />

{% endfor %}
    
12.08.2014 / 21:49