I figured out a weird way to do this a while back but decided it was a
bad idea.  It works, though:

models_a.py:
from django.db import models

class A(models.Model):
    text = models.TextField()
    number = models.IntegerField()

    class Admin:
        pass

models_b.py:
from django.db import models

class B(models.Model):
    phone = models.PhoneNumberField()

    class Admin:
        pass

models.py:
from django.db import models

from models_a import A
from models_b import B

class ref_a_to_b(models.Model):
    a = models.ForeignKey(A, edit_inline=True)
    ref_to_b = models.ForeignKey(B, core=True)

class ref_b_to_a(models.Model):
    b = models.ForeignKey(B, edit_inline=True)
    ref_to_a = models.ForeignKey(A, core=True)

You could also not have these as edit_inline and have a separate form
in the admin for dealing with the relations.

On May 26, 3:20 pm, Tomas Kopecek <[EMAIL PROTECTED]> wrote:
> Tomas Kopecek napsal(a):
>
> > Tim Chase napsal(a):
> > I> does anybody knows, how to implement cross-refering models across files?
> >>   # in example_app/models_a.py
> >>   class A(models.Model):
> >>     # no ref_to_b here
> >>     ...
>
> >>   # in example_app/models_b.py
> >>   import a
> >>   class B(models.Model):
> >>     ref_to_a = models.OneToOneField(a.A,
> >>       related_name='ref_to_b')
>
> >>   # in example_app/models.py
> >>   from models_a import *
> >>   from models_b import *
>
> > Is this correct method for future django releases? Documentation says on
> > one-to-one: "The semantics of one-to-one relationships will be changing
> > soon, so we don't recommend you use them." Maybe this is more question
> > for django-devel...
>
> Moreover, it is not sufficient (general enough) solution. if ref_to_b
> and ref_to_a are two independent many-to-one relations, I can't use
> one-to-one semantics.
>
> --
>
>                         Tomas Kopecek
>                         e-mail: permonik at mesias.brnonet.cz
>                          ICQ: 114483784


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