暫無描述

models.py 700B

123456789101112131415161718192021222324
  1. from django.db import models
  2. class Topic(models.Model):
  3. """A topic the user is learning about."""
  4. text = models.CharField(max_length=200)
  5. date_added = models.DateTimeField(auto_now_add=True)
  6. def __str__(self):
  7. """Return a string representation of the model."""
  8. return self.text
  9. class Entry(models.Model):
  10. """Something specific learned about a topic."""
  11. topic = models.ForeignKey(Topic)
  12. text = models.TextField()
  13. date_added = models.DateTimeField(auto_now_add=True)
  14. class Meta:
  15. verbose_name_plural = 'entries'
  16. def __str__(self):
  17. """Return a string representation of the model."""
  18. return self.text[:50] + "..."