python - How to sort on number of visits in Django app? -


In Django (1.0.2), I have 2 models: Lessons and State Lawson.

  class lessons (models.Model): content = model. TextField () def get_visits (self): Return itself Statlesson_set.all () Calculation () Category StatLesson (models.Model): Lesson = Model. ForeignKey (text) Datetime = models.DateTimeField (default = datetime.datetime.now ())  

Records 1 visit of certain text. I can use lesson.get_visits () to get the number of visits for that lesson.

How do I get a query of the lessons, which is solved with the number of visits? I'm looking for something like this: Lesson.objects.all () Order_by ('statathon__count') (but it does not clearly work)

  class "itemprop =" text "> 

There will be gross support on DJJongo 1.1.

Text (models.Model): Content = Model TestField () visit_count = models.IntegerField (default = 0) Category StatLesson (models.Model): Lesson = Model. Foreign key (text) datetime = models.DateTimeField (default = datetime Datetime.now ()) def save (self, * args, ** kwargs): if self.pk is none: self.lesson.visit_count + = 1 self .lesson.save () super (StatLesson, self) .ave (* Args, ** kwargs)

Then you can query this way:

  Lesson.objects.all (). Order_by ('visit_count')  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -