ManyToMany("self") isn't a supported feature of Django (yet), so many
people suggested to me that I can get around it by making an
intermediary model class, which has two foreign keys to the model I'm
interested in.  Here's what an example scenario looks like:

class Node(models.Model):
    path = models.CharField(maxlength=255,unique=True)
    created_at = models.DateTimeField(null=True)

class Link(models.Model):
    source = models.ForeignKey(Node,related_name='links')
    destination = models.ForeignKey(Node,related_name='links_from')


With this setup, I can perform operations like obtaining all links that
point to a certain node, n:

linkset = n.links_from.all()

Here, 'linkset' is a QuerySet on the Link model.  But what I'm really
doing is trying to obtain a QuerySet on Node.  Why is this useful?
Well, I'd like to do something like order the results by the creation
time of the node.

Does anyone have any advice on how to do this, transforming a QuerySet
on one model into a QuerySet of another?

The obvious answer is to just build my own array and do a manual sort
on that, but I figured that there must be an easier method.

Thanks!
gch


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to