I have the following model:
model rank(Models.model):
username = models.CharField(max_length=200, default=0)
points = models.IntegerField(default=0)
rank = models.IntegerFiel(default=0)
what i want is, based on ‘points’ recalc this model, setting the result in ‘rank’ field.
i=0
user_list = db.Rank.objects.get.all().order_by('-points')
for user in user_list:
user.rank = i
user.save()
i += 1
this works fine, but whit 1800 users i spend 130 MB of MEMORY !!!! Webfaction want kills me 🙂
how can i do this, without spent a lot of memory ?
The immediate cause of the memory leak is probably that you have
DEBUGset to True. With debug on, Django keeps all the queries it runs in memory. Try it with DEBUG off and you should see usage go down considerably.