Hay, i have a model which houses a board
class Board(models.Model):
parent_board = models.ForeignKey('self', blank=True, null=True)
Each board can belong to another board
So say
Linux
Windows
OS X
can belong to a board called
Computing
These boards house a Thread object
class Thread(models.Model):
board = models.ForeignKey(Board)
Now, say i assign a Thread to the Windows board, i can get this object easily.
But i want to list all Threads associated with Computing
The Thread belongs to the Windows board, but it will also belong to the Computing board through association.
How can i run a Query on the computing board and retrieve all threads from it's subboards (as well as any belonging to just the Computing thread)?
I've done it, but it's very crude, i wonder if there a more Django way of doing it
Heres my code of it at the moment (working)
listings = [] # blank list to hold clean values
for board in board.board_set.all(): # for each board
for listing in board.listing_set.all(): # get the listing from each board
listings.append( listing ) # append to the listings list