Answer the question
In order to leave comments, you need to log in
Django dropdown in template. How is it customary to change objects correctly?
Good day!
Please don't drink too much.
I'm trying to master the first trial project in django (just getting to know each other).
I will be grateful for help.
#models.py
grade_list = (
[1, 'Самый низкий']
, [2, 'Низкий']
, [3, 'Средний']
, [4, 'Выше среднего']
, [5, 'Высокий']
, [6, 'Самый высокий']
)
class Request(models.Model):
title = models.CharField(max_length=150)
#....
class Grade(models.Model):
user = models.ForeignKey(User)
request = models.ForeignKey(Request)
level = models.IntegerField(choices=grade_list, default=3)
@login_required(login_url="/login/")
def requests(request):
latest_requests_list = Request.objects.filter(active = True).order_by('average_grade', '-datetime')[:300]
context = {'latest_requests_list': latest_requests_list, 'count_list': count_list}
return render(request, "requests.html", context)
#....
{% for request in latest_requests_list %}
<tr>
<td><a href="/requests/{{ request.id }}/"> {{ request.number }}</a></td>
<td><a href="/requests/{{ request.id }}/">{{ request.datetime }}</a></td>
<td><a href="/requests/{{ request.id }}/">{{ request.title }}</a></td>
<td><a href="/requests/{{ request.id }}/">{{ request.actual_status }}</a></td>
<td><a href="/requests/{{ request.id }}/">{{ request.str_av_grade }} ({{request.average_grade}})</a></td>
<td>
<ul class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
{{ request.cur_grade }}
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
{% for avs in grade_list %} #я в курсе что список не передается. Это просто пример желаемой логики
<li><a href="#">{{avs}}</a></li>
{% endfor %}
</ul>
</ul>
</td>
#....
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question