How to extract django objects having maximal value?

By Fomalhaut

Supposing I have a django model:

class Score(models.Model):
    name = models.CharField(max_length=32)
    value = models.Integer()
    def __unicode__(self):
        return u"{}: {}".format(self.name, self.value)

And the table score looks line this:

id | name  | value
---+-------+------
1  | john  | 15
2  | ivan  | 21
3  | david | 14
4  | john  | 11
5  | john  | 25
6  | david | 8

I want to extract the objects with maximal value for each name given as a list of names. For example:

names = ['john', 'david', 'paul']
dct = process(names) # How to implement this function???
for name, obj in dct.items():
    print name, obj

should print:

john john: 25
david david: 14
paul: None

The performance matters. I am supposed to process around 10k names having around 1k records for each name in score. What is the best way to do it with django? Does it make a sense to use django ORM in this task?

I use MySQL database.

Thanks for advance.

Source: Stack Overflow

    

Share it with your friends!

    Fatal error: Uncaught Exception: 12: REST API is deprecated for versions v2.1 and higher (12) thrown in /home/content/19/9652219/html/wp-content/plugins/seo-facebook-comments/facebook/base_facebook.php on line 1273