python 3.x - Django 1.9: How to make a dynamic form? -
i have model called course:
class course(models.model): number_of_semesters = models.positiveintegerfield() field = models.charfield(max_length=30) qualification = models.foreignkey(qualification, on_delete=models.cascade)
i trying form in can input many courses user wants webpage. how this?
i know old one, recommend use django rest framework. although kind of tricky @ first, can use viewsets , serializers multiple objects , save them in database @ once. (btw, though used api's can substitute normal django views viewsets , use them standard).
i know not asked, have been developing in django while , haven't been able use formsets in clean way save n objects without knowing n @ first.
if decide go proposal, recommend read following:
viewsets
serializers (they same djangoforms)
nested serializers (for rendering/creating/linking foreignkey instance)
# serializer rest_framework import serializers class qualificationserializer(serializers.modelserializer): class meta: model = qualification fields = ( # insert fields here, form ) class courseserializer(serializers.modelserializer): qualification = qualificationserializer() # nested serializer class meta: model = course fields = ( 'number_of_semesters', 'field', 'qualification', )
Comments
Post a Comment