Ok, in my models.py file I’ve just created this:
class PL(models.Model):
created = models.DateTimeField(default=timezone.now)
owner = models.ForeignKey(User, related_name='PL')
text = models.CharField(max_length=2000, blank=True)
rating = models.IntegerField(default=0)
pal = models.ManyToManyField(PS, blank=True, null=True)
class Meta:
verbose_name = "PL text"
def __unicode__(self):
return self.user
class PS(models.Model):
Original = models.ForeignKey(PL, related_name='OPL', blank=True)
rating = models.IntegerField(default=0)
word = models.CharField(max_length=50, blank=True)
def __unicode__(self):
return "Word: %s" % (self.word)
but I keep getting: NameError: name ‘PS’ is not defined
Why is this happening?
Like mgilson says, It goes top to bottom. But Django has a way to overcome it by doing this –
Django doc describes it under ForeignKey.
You can read more here.