I decide to learn Django Forms. For awhile now been using HTML forms because its hard for me to come terms with django forms.
How could i populate initial data to django forms? Example:
Consider if these models are populated. Contain data.
models.py
class Game(models.Model):
title = models.CharField()
genre = models.CharField()
so if i have
view.py
Game_list = Game.objects.all()
return render_to_response('template',locals())
so in template.html i could just:
{% for game in game_list %}
<p> game.title <p> <br /> <p> game.genre <p>
if i wanna populate an initial data on html forms which i usually use:
{% for game in game_list %}
<form action= '/add/' method='POST'>
<input="text" name="title" value="{{game.title}}" />
<input="text" name="genre" value="{{game.genre}}" />
<input type="submit" />
How can i do this in Django Forms? By reading article online,they do this by overriding using forms.init
class Anyforms(forms.Form):
super(Anyforms, self).__init__(*args,**kwargs)
I cant get a hold of how to populate using super. What/How data that forms get during runtime? Any good links that i could read to get me up & running on wrangling django forms?
Does:
<input="text" name="title" value="{{game.title}}" />
<input="text" name="genre" value="{{game.genre}}" />
are the same as this ?
data = {'title':'{{game.title}}','genre':'{{game.genre}}'}
form(data)
Are the variable gonna be replace in template?