I'm trying to make a student management website with Django. Now I want to count how many students are in a single grade and display the number in my website. How can I do that? My model:
from django.db import models
import uuid
from django.core.validators import MaxValueValidator,
MinValueValidator
# Create your models here.
class Student(models.Model):
name = models.CharField(max_length=150)
roll = models.UUIDField(default=uuid.uuid4, unique=True,
primary_key=True, editable=False)
father_name = models.CharField(max_length=150)
mother_name = models.CharField(max_length=150)
phone_number = models.IntegerField(validators=
[MaxValueValidator(99999999999)])
grade = models.ForeignKey('grade', on_delete=models.CASCADE )
def __str__(self):
return self.name
class Grade(models.Model):
grade_name = models.IntegerField(validators=
[MaxValueValidator(10), MinValueValidator(1)])
id = models.UUIDField(default=uuid.uuid4, unique=True,
primary_key=True, editable=False)
def __str__(self):
return self.grade
count()in Django: docs.djangoproject.com/en/3.2/ref/models/querysets/…