logo       

Re: forward declaration: msg#02322

DjangoUsers

Subject: Re: forward declaration


On Fri, Jul 31, 2009 at 1:56 PM, Daymien<reimund.klain@xxxxxxxxxxxxxx> wrote:
>
> Hallo,
>
> How could I implement forward declaration in django models?
> this example wouldn't work for me:
> Has anyone an idear or a solution?
>
> This django model show a simple implementation for a bloodline app!
> ********************************************************************************
> from django.db import models
> from django.contrib.auth.models import User
> from django.contrib import admin
>
> class Parent:
> Â Âpass
> class Child:
> Â Âpass
>
> class AbstractUser(models.Model):
> Â Âuser_id = models.ForeignKey(User, blank=True)
> Â Âbirthday = models.DateField("birthday", blank=True, null=True)
> Â Âday_of_death = models.DateField("day of death", blank=True,
> null=True)
> Â Âparents = models.ManyToManyField(Parent, blank=True, null=True)
> Â Âchilds = models.ManyToManyField(Child, blank=True, null=True)
>
> class Parent(AbstractUser):
> Â Â#user_id = models.ForeignKey(User, blank=True)
> Â Âdef __unicode__(self):
> Â Â Â Âreturn "%s %s" % (self.user_id.first_name,
> self.user_id.last_name)
>
> class Child(AbstractUser):
> Â Â#user_id = models.ForeignKey(User, blank=True)
> Â Âdef __unicode__(self):
> Â Â Â Âreturn "%s %s" % (self.user_id.first_name,
> self.user_id.last_name)
>
> class MyUser(AbstractUser):
> Â Â""" Represent a User for this site
> Â Â"""
> Â Âdef __unicode__(self):
> Â Â Â Âreturn "%s %s" % (self.user_id.first_name,
> self.user_id.last_name)
>
> admin.site.register(MyUser)
> admin.site.register(Parent)
> admin.site.register(Child)
> ********************************************************************************
> I got this error message:
> AssertionError: ManyToManyField(<class
> stammbaum.bloodline.models.Parent at 0x84fc11c>) is invalid. First
> parameter to ManyToManyField must be either a model, a model name, or
> the string 'self'
>
> regards
> R.Klain
> >
>

Take a look at how you can pass the string name of the class to avoid
this issue:
http://docs.djangoproject.com/en/dev/ref/models/fields/#module-django.db.models.fields.related

Alex

--
"I disapprove of what you say, but I will defend to the death your
right to say it." -- Voltaire
"The people's good is the highest law." -- Cicero
"Code can always be simpler than you think, but never as simple as you
want" -- Me

--~--~---------~--~----~------------~-------~--~----~
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@xxxxxxxxxxxxxxxx
To unsubscribe from this group, send email to
django-users+unsubscribe@xxxxxxxxxxxxxxxx
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Google Custom Search

News | Mail Home | sitemap | FAQ | advertise