相关文章推荐
睿智的火锅  ·  Official Google Blog: ...·  2 周前    · 

I am trying to get the total count of occurrence of a field in same model in django. Is it possible to do it or not?

for example I have a model as below:

class Blog(DateTimeModel):

title = models.CharField(max_length=255)

description = models.TextField()

category = models.CharField(max_length=255, null=True, blank=True)

and a table of data as below:

id | title                               | description          | category
----+-------------------------------------+----------------------+----------
1 | blog title first                    | description 1        | social
2 | blog title second                   | description 2        | social
3 | blog title third                    | description 3        | community
4 | blog title fourth                   | description 4        | community
5 | blog title fifth                    | description 5        | people

I want a result to be as:

<QuerySet [{'category': 'social', 'blog_count': '2'}, {'category': 'community', 'blog_count': '2'}, {'category': 'people', 'blog_count': '1'}]>

  • E&ICT MNIT - Data Science and Machine Learning | IIT Madras - Advance Certification in Data Science and AI | E&ICT IIT Guwahati - Cloud Computing & DevOps | E&ICT IIT Guwahati - Cyber Security | E&ICT IIT Guwahati - Software Engineering & Application Development | E&ICT IIT Guwahati - Big Data Analytics | E&ICT IIT Guwahati - Full Stack Web Development | E&ICT MNIT - AI and Machine Learning | E&ICT IIT Guwahati - UI UX Design Strategy | IIT Madras - Data Analytics for Business | E&ICT IIT Roorkee - Cloud Computing & DevOps | E&ICT MNIT - Cyber Security & Ethical Hacking | E&ICT MNIT - Business Analyst & Project Management

    Browse By Domains

    Big Data Analytics Courses | Data Science Courses | Business Intelligence courses | Best Salesforce Courses | Cloud Computing Courses | Best Digital Marketing Courses | Programming Courses Online | Database Certification Courses | Project Management Certification Courses | Best Web Development Certification courses | Automation Trainings | UI UX Course

    Popular Courses

    Data Science Courses | Best Artificial Certification Intelligence Course | Machine Learning Training | Python Course | DevOps Certification Course | AWS Training and Certification | Azure Certification | AWS DevOps Training | Azure DevOps Certification Course | Cyber Security Course | Ethical Hacking Course | Big Data Hadoop Certification | SQL Course | Salesforce Admin Certification | Online Salesforce Developer Certification | Selenium Training Online | Business Analyst Course Online | Data Analyst Certification course | Best Microsoft Power BI Certification Course | Tableau Course Online | Linux certification Course | Data Analytics Certification Course | Digital Marketing Course | Online Business Analytics Course | Online Investment Banking Course | Online Supply Chain Course | Online Electric Vehicle Course

    Degree Courses

    M. Tech in AI & ML | M. Sc. in Data Science | MBA in Big Data Management | M. Sc. in Artificial Intelligence | MBA in Business Administration | MBA in International Marketing | Master’s in Computer Science | MBA in Finance and Accounting | Master’s in Engineering Management | Master of Science in Data Science | MSC in Data Science