Class definition order between two related classes

7 views
Skip to first unread message

buzz

unread,
Aug 13, 2008, 5:05:27 AM8/13/08
to Django developers
I have this relationship in my models.py:

===================
from django.db import models

class A(models.Model):
b_primary = models.ForeignKey(B)

class B(models.Model):
a_collection = models.ManyToManyField(A)

===================

when I try to run this, it complains about B not being defined. If I
switch the order, it complains about A not being defined. This is
probably more a python question then django-specific, but I couldn't
find an answer to this using Google... So, is there a way to make this
kind of relationship possible?

Waylan Limberg

unread,
Aug 13, 2008, 8:48:41 AM8/13/08
to django-d...@googlegroups.com
buzz,

Questions like this should be directed to the django-users group.
Django-developers is for discussing the development of django itself,
not development using Django.

But to answer your question, try wrapping your ForeignKey reference in quotes:

b_primary = models.ForeignKey("B")

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

Reply all
Reply to author
Forward
0 new messages