James, one thing you might consider is creating an M2M relation between
edges and nodes.  That won't allow you to enforce at a database level the
rule that edges relate to exactly one or two nodes, but it will work pretty
naturally at the model level -- each node has a set of related edges, and
each edge has a set of related nodes.

  -- Scott

On Wed, May 14, 2008 at 3:43 AM, James Tauber <[EMAIL PROTECTED]> wrote:

>
> On a couple of occasions, I've had need for a model that links two
> instances of another model and I'm wondering about the best practices
> for doing this.
>
> Abstractly, there's an undirected graph where both nodes and arcs are
> objects.
>
> Concretely, two examples are:
>
> 1) roads in django-mmo existing between two hubs but the roads aren't
> directed: A to B means the same as B to A
>
> 2) friendship in django-friends existing between two users where
> friendship is necessarily mutual:  a Friends b => b Friends a
>
> Obviously this can be done with Road or Friendship having two foreign
> keys but (a) this leads to a superfluous related_name; (b) how do you
> best query a node for its arcs?
>
> If the arc were just a M2M field on the node, one could use
> symmetrical=True but it isn't clear to me the best way to do this
> where the arc/association is its own model.
>
> James
> --
> James Tauber              http://jtauber.com/
> journeyman of some   http://jtauber.com/blog/
>
>
>
>
>
> >
>


-- 
http://scott.andstuff.org/ | http://truthadorned.org/

--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to