Skip to content Skip to sidebar Skip to footer

Fill Django Form Using Bootstrap Selectbox

i have a django form for add new data to my database & a Bootstrap Selectbox how can i fill form with that selectbox's items ?? html :

Solution 1:

You could hack this together with some javascript code to handle the selection to copy the student and lesson details from the drop down boxes into the form but then why not just fix the model in the first place.

classlesson_student(models.Model):
    lesson = models.ForeignKey(Lesson)
    student = models.ForeignKey(Student)

Now, not only do you have details about their codes... you have the full models to available. You also will not have anything else left to do in terms of your form since the ModelForm will take care of that.


i have problem in my list ..... in student or lesson list i have "Student Object" & "Lesson Object" instead of names

Thats because you haven't provided a string representation for your models.

I.e

classstudent(models.Model):
    First_Name = models.CharField(max_length=100,null=True)
    Last_Name = models.CharField(max_length=100,null=True)
    STNO = models.CharField(max_length=10,null=True)

    def__str__(self):
         return"{0} {1}".format(self.First_Name, self.Last_Name)

Post a Comment for "Fill Django Form Using Bootstrap Selectbox"