On Fri, Jul 31, 2009 at 1:56 PM, Daymien<reimund.kl...@googlemail.com> 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@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 -~----------~----~----~----~------~----~------~--~---