Monday 15 March 2010

sql - Implementing Sticky Threads In Django -


Note: I am new to both DJGengo and database, so please seduce my ignorance.

I am trying to apply a platform to the DJ and I want sticky threads

  square thread (models.Model): title = models.CharField (MAX_LENGTH = max_title_length) Author = Model was inexplicably the way that I was thinking about doing this to define the thread model like this. FiorignKey (Player, related_name = "nonsticky_threads") POST_DATE = models.DateField ( ) Parents = models.ForeignKey (subsection, related_name = "nonsticky_threads") turned off = models.BooleanField () sticky = models.BooleanField ()   

and more To get sticky threads, something like this :.

  sticky_threads = filter to Thread.objects.all () (sticky = true)   

The problem is that at least theoretically it o ( N), which seems bad. (Since sticky threads are always always displayed on the first page, but this query continues for a long time) However, I do not know that the database / Dzongo cleverness will affect the final performance or if it still worsens. <

 <

class thread (models.model): title = models.CharField (MAX_LENGTH = max_title_length) Author = models.ForeignKey (Player p> My current options also separate threads and Sticky_Thread Classes to create, related_name = "nonsticky_threads") POST_DATE = models.DateField () parent = models.ForeignKey (subsection, related_name = "nonsticky_threads") closed = models.BooleanField () class Sticky_Thread (models.Model ): Title = models.CharField (MAX_LENGTH = max_title_length) author = models.ForeignKey (player, related_name = "sticky_threads") POST_DATE = models.DateField () parent = models.ForeignKey (subsection, related_name = "sticky_threads") closed Done = models.BooleanField ()

I do not make any difference in O (1) time catching the sticky thread, I do not like what about this approach, it is that if I want to get all the threads of a player now, then I like this one Special Thread property must be implemented:

  class player (model model): [snip] @ Property deed threads (self): returns self Sticky_threads | Self-contradictory_read   

And this approach feels ugly.

Is there a clearly best way to do something like this? Do I need time to see if the naïve way is acceptable or not? (I am applying it as an exercise to learn, so I do not really have harsh limits, which makes it a bit difficult) (If so, how would you recommend that I do this? A better choice?

Thanks!

Your analysis of the complexity of those two tasks The way is closed. Classification of filter operations in the form of O (n) is not really true and o (1) Two different classes in the form - I do not know what you are using to create this distinction. Optimized to choose individual criteria: An index filter query on the sticky column is approx Make a question similar to everything from a different table.

The first method without question is the right way to go about this, as long as you make sure that your Sticky column The Nukrmit.

No comments:

Post a Comment