directed graph in default admin

11 views
Skip to first unread message

John Lenton

unread,
Oct 24, 2006, 11:31:36 AM10/24/06
to django...@googlegroups.com
Hi all.
I've got an app where I have a table of nodes, and a table of directed
edges between those nodes. I.e,

-----8<--
class Node(models.Model):
name = models.CharField(maxlength=20, core=True, blank=False)
def __str__(self):
return self.name

class Admin:
pass

class Path(models.Model):
source = models.ForeignKey(Node, core=True, related_name='source_set')
sink = models.ForeignKey(Node, core=True, related_name='sink_set')

def __str__(self):
return "from %s to %s" % (self.source, self.sink)

class Admin:
list_display = ['source', 'sink']
-->8-----

that works very nicely. Or does it? The link on the sink column in the
admin interface sorts by source :(

What am I missing? Oh, python2.4, django from svn, linux.

--
John Lenton (jle...@gmail.com) -- Random fortune:
The trouble with a lot of self-made men is that they worship their creator.

Guillermo Fernandez Castellanos

unread,
Oct 26, 2006, 4:29:25 AM10/26/06
to django...@googlegroups.com
Cheers,

have a look at the Meta options order_with_respect_to and ordering:
http://www.djangoproject.com/documentation/model_api/#order-with-respect-to

Hope it helps,

G

John Lenton

unread,
Oct 26, 2006, 5:23:46 PM10/26/06
to django...@googlegroups.com
On 10/26/06, Guillermo Fernandez Castellanos

<guillermo.ferna...@gmail.com> wrote:
>
> Cheers,
>
> have a look at the Meta options order_with_respect_to and ordering:
> http://www.djangoproject.com/documentation/model_api/#order-with-respect-to

no, that's not it. Or I didn't understand how to use it; at any rate,
it didn't work. Let me explain a little better the situation: Here is
the admin screen as it comes up:

Source | Sink
Cnode | Bnode
Anode | Cnode
Xnode | Anode
Mnode | Anode

if you click on "Source", it sorts by the source's name, as expected:

Source v | Sink
Anode | Cnode
Cnode | Bnode
Mnode | Anode
Xnode | Anode

this is as expected; but if you click on "Sink", you get

Source | Sink v
Anode | Cnode
Cnode | Bnode
Mnode | Anode
Xnode | Anode

i.e., it still sorts by Source instead of Sink. Is this a bug in
django, or am I forgetting something?

Waylan Limberg

unread,
Oct 27, 2006, 10:27:19 AM10/27/06
to django...@googlegroups.com
On 10/26/06, John Lenton <jle...@gmail.com> wrote:
>
[snip]

>
> this is as expected; but if you click on "Sink", you get
>
> Source | Sink v
> Anode | Cnode
> Cnode | Bnode
> Mnode | Anode
> Xnode | Anode
>
> i.e., it still sorts by Source instead of Sink. Is this a bug in
> django, or am I forgetting something?
>

I couldn't help but notice that in your example, it is also sorted by
Sink *descending*. What happens if you click on "Sink" again? If I'm
not mistaken, it should sort *ascending*. Then again, this just may be
a coincidence of a poorly written example in which case you can ignore
me.


--
----
Waylan Limberg
way...@gmail.com

John Lenton

unread,
Oct 27, 2006, 4:25:20 PM10/27/06
to django...@googlegroups.com
On 10/27/06, Waylan Limberg <way...@gmail.com> wrote:
>
> I couldn't help but notice that in your example, it is also sorted by
> Sink *descending*. What happens if you click on "Sink" again? If I'm
> not mistaken, it should sort *ascending*. Then again, this just may be
> a coincidence of a poorly written example in which case you can ignore
> me.

sorry, just a poor example. The real table has rather long names and
over 15k entries, so I can't exactly paste it here.

Well, I just copy and paste the first few rows... yeah. Here goes:

when it first comes up, it starts like this:
====


Source Sink
ALDENE 13 KV SK NUG AECO
ELRAMA 13 KV UNIT1 HREA - AP
ALDENE 13 KV SK NUG APS
MITCHELL 24 KV GEN 3 DUQ
ALDENE 13 KV SK NUG BGE
====

then I click on Source, and I get

====
Source Sink
ALDENE 13 KV SK NUG WILLIAMSPORT - AP
ALDENE 13 KV SK NUG WESTERN HUB
ALDENE 13 KV SK NUG WEST INT HUB
ALDENE 13 KV SK NUG WELLSBORO
====

and I click on Sink, and get
====
Source Sink
ALDENE 13 KV SK NUG WILLIAMSPORT - AP
ALDENE 13 KV SK NUG WESTERN HUB
ALDENE 13 KV SK NUG WEST INT HUB
ALDENE 13 KV SK NUG WELLSBORO
====

which is exactly the same as the previous one, if you look :(

Reply all
Reply to author
Forward
0 new messages