V
V
val1n0r2020-02-24 19:10:15
MySQL
val1n0r, 2020-02-24 19:10:15

How to correctly count the number of matches in a table?

Ku

There is such a table

5e53f4413cba2032807344.png

In it, as you can see, there are levels
How to pull out all the levels of portals and count the number of identical levels using django orm?
models.py

class InvPortal(models.Model):
    user_portal = models.ForeignKey(User,on_delete=models.CASCADE)

    portal_name = models.CharField(max_length=65,default='Портал')
    portal_level = models.IntegerField(default=1)
    portal_xp_reward = models.IntegerField(default=100)
    portal_silver_reward = models.IntegerField(default=250)
    portal_info = models.TextField(default='Инфо',max_length=300)
    portal_unique_id = models.CharField(max_length=65,default=unique_id)
    portal_time_taken = models.IntegerField(default=15)
    portal_selected = models.BooleanField(default=False)
    
    def __str__(self):
        return self.portal_name


The output would be something like
level_18 = 5 # 5 = количество порталов
level_7 = 2 # 2 = количество порталов


Thanks to

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Russian Federation, 2020-02-24
@val1n0r

InvPortal.objects.values('portal_level').distinct().count()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question