Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have 3 models categories, badges, and reward. The users are awarded badges and are stored under reward. The user model is the default model provided by django.

class BadgeCategory(models.Model):
    name = models.CharField(max_length=30)

class Badge(models.Model):
    points = models.IntegerField(default=1)
    title = models.CharField(max_length=30)
    category = models.ForeignKey(BadgeCategory,on_delete=models.SET_NULL,null=True)


class Reward(models.Model):
    awarded_by = models.CharField(max_length=30)
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    badges = models.ForeignKey(Badge, on_delete=models.CASCADE)

BadgeCategory refers to the category under which the badge falls, Badge refers to various badges. and reward contains all the various badges given to users. I am looking to find a query such that I get the following format of the output

Username category 1 category 2
user 1 count(category 1) count(category 2)
user 2 count(category 1) count(category 2)
question from:https://stackoverflow.com/questions/65891230/querying-between-multiple-django-models

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
403 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...