views:

11

answers:

1

Hi, i've this code:

from django.db import models

class Entry(models.Model):
    title =     models.CharField(max_length=30,null=False)
    body_text = models.TextField(max_length=255)
    author =    models.ForeignKey(User)

    def __unicode__(self):
        return self.title

    class Meta:
        ordering = ('title',)

class User(models.Model):
    nick = models.CharField(max_length=25)
    pwd = models.CharField(max_length=50)
    entries = models.ManyToManyField(Entry)

So, i have a model "Entry" that have a field of type User called "author". The problem is that the User model not been created yet, so when i run syncdb i get an error.

Can anybody help me to fix this problem ?

+2  A: 

You don't need to reference the relationship between the models in both class definitions. Try this instead:

class User(models.Model):
    nick = models.CharField(max_length=25)
    pwd = models.CharField(max_length=50)

class Entry(models.Model):
    title =     models.CharField(max_length=30,null=False)
    body_text = models.TextField(max_length=255)
    author =    models.ForeignKey(User)

    def __unicode__(self):
        return self.title

    class Meta:
        ordering = ('title',)
Joshmaker
And change models.ForeignKey to models.ManyToManyField if each entry can have multiple authors
Joshmaker
thanks Joshmaker :-D
Agusti-N