I have model called StudentAppeared
class StudentAppeared(models.Model):
roll_number = models.CharField(max_length=50)
Assume i have following data

From the above data result should display

How can i achieve this thing using django query for StudentAppeared model?
StudentAppeared.objects.distinct()
sorry made a mistake. fixed it
This returns unique roll_numbers with the highest associated id, sorted by id:
from django.db.models import Max
stats = (
StudentAppeared.objects
.values('roll_number')
.annotate(max_id=Max('id'))
.values_list('max_id', 'roll_number ')
.order_by('max_id')
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With