models.py
class Book(models.Model):
title = models.CharField()
genre = models.ManyToManyField(Genre)
class Genre(models.Model):
name = models.Charfield()
class ReadBook(models.Model):
genre = models.ForeignKey(Genre)
books = models.ManyToManyField(Book)
Also I have one ModelForm:
class ReadBookForm(ModelForm):
class Meta:
model = ReadBook
template.html
<form action="/add_report/" method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Submit" />
</form>
The purpose: By default to show a visitor only one field - genre. When he is with done this choice - show other fields from books model, related to selected genre.
inside form tag:
then in javascript (jQuery is great for this stuff):
you must create a view that will return a html that should be placed in this div:
and of course add this view to the urls.py.
One of many solutions :) didnt' test it (written only here, so maybe small bugs somewhere) :)