Create your models: Authors

  1. Posts
  2. Create your models
  3. Topics

Above the Post model, add an Author model. It has to be above the Post model, because the Post model references it as a ForeignKey.

class Author(models.Model):

firstname = models.CharField(max_length=80)

lastname = models.CharField(max_length=100)

bio = models.TextField()

homepage = models.URLField(blank=True)

changed = models.DateTimeField(auto_now=True)

class Meta:

unique_together = (('firstname', 'lastname'),)

def __unicode__(self):

return self.firstname + ' ' + self.lastname

Some luddites don’t have home pages, so we allow that field to be blank. We also require that no author have the same first name and last name. Otherwise, we’d always make mistakes setting the author if we gave two people the same name. If two people have similar names, they’ll need to differentiate themselves some way, such as using a middle initial or middle name.

  1. Posts
  2. Create your models
  3. Topics