1👍
✅
You can do this with many ways, one of the easiest one is using django-smart-selects app, which integrate very well specially if you’re using django admin. All you have to do is to install the app and update your model:
from smart_selects.db_fields import ChainedManyToManyField
class Options (models.Model):
book = models.ForeignKey(Book, help_text='Text', null=True, blank=True)
languages = ChainedManyToManyField(Language, related_name='languages', help_text='Languages'
chained_field="book",
chained_model_field="languages")
0👍
You can make it via AJAX. When the user selects a book you call the url of your view in Django.
The view will make a form with id of the book the user selected, then it will return only the html for the form you want. Then, in the ajax success you put the html form where you want it.
- Serialize DynamicField
- Create a select in template from list
- Unable to inject factory into test suite using Karma/Jasmine
Source:stackexchange.com