Create multiple form form one modelform class

Hey guys,
I am working on a project for evaluating teachers in school. But, at one stage I am stuck and nobody answered my question on StackOverflow; don’t know why!. Anyway, I want to build a model form from my Student_Answer class in a specific way. On the template, I want the model form to work this way;

< Teacher >
< Department>
< Subject>
< Semester>

  1. Question
    • weak
      -normal
      -good
      -excellent
  2. Question
    • weak
      -normal
      -good
      -excellent

I tried formset but the problem is I have multiple forms similar to each other. I have to select everything for every single question.
Is it possible to do such things with modelform ?

models.py
RATING_CHOICES = ((1, “Weak”), (2, “Average”), (3, “Good”), (4, “Excellent”))
SEMESTER = ((1, ‘1’), (2, ‘2’), (3, ‘3’), (4, ‘4’), (5, ‘5’), (6, ‘6’))

class Question(models.Model):
question = models.CharField(max_length=200)

def __str__(self):
    return self.question

class Department(models.Model):
name = models.CharField(max_length=60)

def __str__(self):
    return self.name

class Semester(models.Model):
num = models.IntegerField(choices=SEMESTER, default=1)

class Subject(models.Model):
name = models.CharField(max_length=100)
code = models.CharField(max_length=5, null=True)
semester = models.ForeignKey(Semester, on_delete=models.CASCADE)
department = models.ManyToManyField(Department)

def __str__(self):
    return self.name


class Teacher(models.Model):
name = models.CharField(max_length=200)
last_name = models.CharField(max_length=200, null=True)
department = models.ManyToManyField(Department)
subject = models.ManyToManyField(Subject)

def __str__(self):
    return self.name


class Student_Answer(models.Model):
teacher = models.ForeignKey(Teacher, on_delete=models.CASCADE)   
question = models.ForeignKey(Question, on_delete=models.CASCADE)
subject = models.ForeignKey(Subject, on_delete=models.CASCADE)
department = models.ForeignKey(Department, on_delete=models.CASCADE)
semester = models.ForeignKey(Semester, on_delete=models.CASCADE)
answer = models.SmallIntegerField(choices=RATING_CHOICES, default=1)

forms.py

class StudentForm(ModelForm):
     class Meta:
         model = Student_Answer
         fields = '__all__'
         widgets = {
             'answer': RadioSelect(choices=RATING_CHOICES)
         }

See Model formsets - formsets built from model forms.

But formset generate same form with similar fields which I don’t want that.

Can you be more explicit as to what you’re trying to achieve? It’s not clear from what you’ve posted what it is that you’re trying to do here.

look this is the output of using formset.

which is not logical.

what I want my modelform to generate is like this

So your model form is used for the first four fields - then you can use an Inline model formset for the individual ratings.

sounds reasonable. Could you please show me an example ?

Unfortunately, I don’t have one to share.

You already know how to work with formsets. The Inline formset is just a wrapper around regular formsets allowing you to specify a parent class instance (see the previously referenced docs page).

Okay I am going to try it.