models.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Copyright: (c) OpenSpug Organization. https://github.com/openspug/spug
  2. # Copyright: (c) <spug.dev@gmail.com>
  3. # Released under the AGPL-3.0 License.
  4. from django.db import models
  5. from libs.mixins import ModelMixin
  6. import json
  7. class Notice(models.Model, ModelMixin):
  8. title = models.CharField(max_length=100)
  9. content = models.TextField()
  10. is_stress = models.BooleanField(default=False)
  11. read_ids = models.TextField(default='[]')
  12. sort_id = models.IntegerField(default=0, db_index=True)
  13. created_at = models.DateTimeField(auto_now_add=True)
  14. def to_view(self):
  15. tmp = self.to_dict()
  16. tmp['read_ids'] = json.loads(self.read_ids)
  17. return tmp
  18. class Meta:
  19. db_table = 'notices'
  20. ordering = ('-sort_id',)
  21. class Navigation(models.Model, ModelMixin):
  22. title = models.CharField(max_length=64)
  23. desc = models.CharField(max_length=128)
  24. logo = models.TextField()
  25. links = models.TextField()
  26. sort_id = models.IntegerField(default=0, db_index=True)
  27. created_at = models.DateTimeField(auto_now_add=True)
  28. def to_view(self):
  29. tmp = self.to_dict()
  30. tmp['links'] = json.loads(self.links)
  31. return tmp
  32. class Meta:
  33. db_table = 'navigations'
  34. ordering = ('-sort_id',)