On Fri, Feb 11, 2011 at 3:09 PM, Coen <c...@coachcoen.com> wrote:
> For an email discussion list application I'm setting up the following
> model:
>
> Members and EmailAddress(es)
> Each Member has multiple EmailAddress(es), and one PostingAddress
>
> Definition (abbreviated):
>
> class Member(models.Model):
>    PostingAddress = models.ForeignKey(EmailAddress)   # <<<< error in
> this line
>    FirstName = models.CharField(blank = True, max_length = 255)
>    # Snip #
>
> class EmailAddress(models.Model):
>    EmailAddress = models.EmailField()
>    Member = models.ForeignKey(Member)
>    # Snip #
>
> This gives "NameError: name 'EmailAddress' is not defined". When I
> swap these two classes around I get the same thing, but for the
> EmailAddress.Member field
>
> One alternative is to add a boolean field to the EmailAddress class to
> say it is the posting field, i.e. change the database structure. But
> is there a way to get this structure to work?
>
> Thanks
>

http://docs.djangoproject.com/en/1.2/ref/models/fields/#django.db.models.ForeignKey

"""
If you need to create a relationship on a model that has not yet been
defined, you can use the name of the model, rather than the model
object itself:
"""

Eg:


class Member(models.Model):
   PostingAddress = models.ForeignKey('EmailAddress')

Also, its bad form to have members named exactly the same as the
class. Typically, you should use lower_case_with_underscores or
mixedCapCamelCase for members and CamelCase for class names.

Cheers

Tom

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to