Answer the question
In order to leave comments, you need to log in
How to fix this search?
model.py
class Author(models.Model):
gender = (('M', 'Male'), ('F', 'Female'))
name = models.CharField(max_length=100)
pol = models.CharField(max_length=1, choices=gender)
birth = models.DateField(max_length=100)
class Book(models.Model):
name = models.CharField(max_length=100)
authors = models.ManyToManyField(Author)
шаблон
form action="{% url 'knig-avtor' %}" method="GET"> {%csrf_token %}
<p>Книги
select name="bok_avt">
{% for ba in books %}
option value="{{ ba.id }}">{{ ba.name }} </option>
{% endfor %}
/select>
input type="submit" value="Найти">
</p>
/form>
views.py
def knig_avtor(request):
a_id = request.GET['bok_avt']
booksa = Author.objects.get(id=a_id)
return render(request, 'app/author_book.html', {'booksa':booksa})
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