Answer the question
In order to leave comments, you need to log in
How to correctly count the number of matches in a table?
Ku
There is such a table
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
level_18 = 5 # 5 = количество порталов
level_7 = 2 # 2 = количество порталов
Answer the question
In order to leave comments, you need to log in
InvPortal.objects.values('portal_level').distinct().count()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question