won't this work for you:
class Node(Model):
parent = ForeignKey('self', blank=True, null=True)
... rest of your model...
then fetch it like Node.objects.filter(parent__isnull=True)
if you are worried with the possibility of ending up with mode that
one root node you could do either (both seem a little hackish though):
a) have a is_root field on your model (still possible to have more than
one though)
b) implement a check on the model's save such as:
def save(self):
if len(Node.objects.filter(parent__isnull=True)) >0:
#node already exists => return or raise
raise "bad, root node already exists"
super(Node, self).save()
(or maybe implement a custom manager for this?)
arthur
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---