1👍
Report_Shope.objects.values('shop_name').annotate(
shop_count=Count('id')
).order_by('shop_count')
👤avd
0👍
You can use count()
Report_Shop.objects.filter(barcode='value').count()
and to sort you can add meta in your model to default order
class Report_Shop(models.Model):
barcode = models.CharField(max_length=500)
email = models.CharField(max_length=500)
shop_name = models.CharField(max_length=500)
class Meta:
ordering = ('-barcode',)
or in your queryset with orfer_by()
Report_Shop.objects.order_by('barcode')
Report_Shop.objects.order_by('-barcode')
The negative sign in front of “-barcode” indicates descending order. Ascending order is implied. To order randomly, use “?”.
- MultipleChoiceField on multiple columns
- (django) (docker) Django webserver wont start
- Looping over JSONResponse() result from django in jquery
- Django form in a base class
- {{object.image.url}} and {{object.image.path}} show as unknown in template where as {{object.image]} shows the path [Django]
Source:stackexchange.com