On 4/4/06, Grimboy <[EMAIL PROTECTED]> wrote:

Basically I want a Model that relates with itself, the relationship
its self will also have data. (That's why I've made it a seperate
Model).


Firstly: You can forward reference a model by using its name as a string ( e.g., ForeignKey("foo") works, in the same way that ForeignKey("self") works). However, IIRC, this only works with ForeignKeys in 0.91. In magic-removal, this has been fixed to encompass all field types.

Second: To build an annotated m2m relation, what you probably want to do is something like:

class Foo(Model):
    data = "">
class Relation(Model):
    from = ForeignKey(Foo, related_name="from")
    to = ForeignKey(Foo, related_name="to")   
    data = "">
Internally, this is very similar to what Django does with m2m fields, except that you get to piggyback your own data, but you don't get the m2m helper functions.

Two caveats on this approach:

1) 0.91 has some problems with having multiple keys on the same table. I don't recall if this affects foreign keys, so be on the lookout for errors/wierd behaviour (e.g., you think you specifiy 'from', but you get the result you expect to be in 'to'). These problems have been resolved in magic-removal.

2) The query syntax in 0.91 isn't bidirectional - so you will have to construct your queries from the Relation outwards. i.e., Foo.get_list(from__data__exact='123') won't work. As a result, writing queries might not be as natural as you would like, Again, this has been rectified in magic-removal.

Russ Magee %-)

--~--~---------~--~----~------------~-------~--~----~
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