class TopCountries(models.Model):
top_countries = JSONField(null=True)
top_countries - это JSONField
'top_countries': [
{'country_code': 'AX', 'country_name': 'Åland Islands'},
{'country_code': 'AL', 'country_name': 'Albania'},
{'country_code': 'DZ', 'country_name': 'Algeria'}
]
Я новичок в расширенных запросах. Я пробовал запрос ниже, но он не дает мне желаемый вывод.
Запрос:
TopCountries.objects.aggregate(Count('top_countries'))
Вывод:
{'top_countries__count': 1}
Желаемый вывод:
{'top_countries__count': 3}