Reputation: 2699
This is very simple. I have a database of objects with pin attributes.
use case
What is the simplest way to accomplish this in django?
index.html
<form action="/polls/" method="post">
{% csrf_token %}
<p>
<label for="pin">Enter group pin:</label>
<input id="pin" type="text" name="pin" maxlength="4" />
<input type="submit" value="View Polls" />
</p>
</form>
Currently it's hard coded in
{% for poll in latest_poll_list %}
{% if poll.pin == "1234" %}
<ul class="poll-list">
<li><a href="/polls/{{ poll.id }}/">{{ poll.question }}</a> - {{poll.pin}}</li>
</ul>
{% endif %}
{% endfor %}
Upvotes: 0
Views: 63
Reputation: 4558
I am pretty new to django so there may be a better solution, but I'll give it a try.
In your view you can do something like this. Considering your code I assume you have a class
Poll
poll = Poll.objects.filter(pin=request.POST['pin'])
Upvotes: 1