have a Detail Model which has a ForeignKey() of User Model. I want to show 
the list of subject (which is a field of Detail Model) associated with a 
single user, at the Front End in Template. It should be a dropdown menu and 
user should be able to select the subject from the list and submit the form.

How should I accomplish it?


Below is my models.py:

class Detail(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    subject = models.CharField(max_length=50)
    skype_session_attendance = models.FloatField()
    internal_course_marks = models.FloatField()
    programming_lab_activity = models.FloatField()
    mid_term_marks = models.FloatField()
    final_term_marks = models.FloatField()

    def __str__(self):
        return f'{self.subject, (self.user.username)} Details'


Below is my views.py:

def performanceCalculator(request):
    if request.method == 'POST':
        performance_form = PerformanceCalculatorForm(request.POST)

        if performance_form.is_valid():
            sub = performance_form.cleaned_data['subject']

            detail = Detail.objects.all().filter(user=request.user, 
subject=sub).first()

            result = fuzz_algo(detail.skype_session_attendance,
                detail.internal_course_marks, detail.programming_lab_activity,
                detail.mid_term_marks, detail.final_term_marks)

            messages.success(request, result)

            return redirect('performance_calculator')
    else:
        performance_form = PerformanceCalculatorForm()

    context = {
        'performance_form': performance_form,        
    }

    return render(request, 'users/performance_calculator.html', context)


and below is my forms.py:

class PerformanceCalculatorForm(forms.Form):
    subject = # what should I put here in order to make a dropdown list?

    class Meta:
        fields = ['subject']



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/80a6b211-3b38-456d-adb4-067c7dd39991%40googlegroups.com.

Reply via email to