I have django models such as this
class District(models.Model):
name = models.CharField(max_length=30,unique=True)
number = models.PositiveIntegerField(null=True,blank=True)
def __unicode__(self):
return "District (%s,%s)" % (self.name,self.number)
class Meta:
db_table = 'districts'
And i can be able to enter district names along with their number. What i would like to be able to do is to view these districts that have been entered in a custom template that i have created. Currently the template has a dropdown option using the select tag. How can i be able to pull the data thats entered using the django model and display it in the template that i have created. This is the current code snippet of what is in the html template
<label for="district"> District</label>
<select id="district" name="district">
<option id="kampala" value="k">Kampala</option>
<option id="mbale" value="m">Mbale</option>
</select>
In your view, pass the District objects to the view’s context like this :
and then in your template (mytemplate.html) do like this:
I hope it helps !