models.py 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. from django.db import models
  2. from django.contrib.auth.models import User
  3. class Tag(models.Model):
  4. Name = models.CharField(blank=False, max_length=50)
  5. class ArticleClass(models.Model):
  6. Name = models.CharField(blank=False, max_length=50)
  7. class Article(models.Model):
  8. ArticleId = models.AutoField(primary_key=True)
  9. Publisher = models.ForeignKey(User, on_delete=models.CASCADE, related_name='Publisher')
  10. Title = models.CharField(blank=False, max_length=50)
  11. Content = models.TextField(blank=False)
  12. Cover = models.URLField(blank=True, max_length=5000)
  13. Read = models.IntegerField()
  14. Like = models.IntegerField()
  15. Publish_Time = models.DateTimeField(auto_now_add=True)
  16. Edit_Time = models.DateTimeField(auto_now=True)
  17. Tag = models.ManyToManyField(Tag, blank=True)
  18. Class = models.ForeignKey(ArticleClass, on_delete=models.SET_NULL, null=True)
  19. class Draft(models.Model):
  20. DraftId = models.AutoField(primary_key=True)
  21. Poster = models.ForeignKey(User, on_delete=models.CASCADE, related_name='Poster')
  22. Title = models.CharField(blank=True, max_length=50)
  23. Content = models.TextField(blank=True)
  24. Add_Time = models.DateTimeField(auto_now_add=True)
  25. Edit_Time = models.DateTimeField(auto_now=True)