news_info.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. # -*- coding: utf-8 -*-
  2. from odoo import models, fields, api
  3. class News(models.Model):
  4. _name = 'news.info'
  5. _description = 'News Info'
  6. _order = 'create_time_ts DESC'
  7. name = fields.Char(string='Title', required=True)
  8. context = fields.Text(string='Context')
  9. context_simple = fields.Char(string='Context Simple', compute='_compute_context')
  10. source_url = fields.Char(string='Source URL')
  11. link = fields.Char(string='Link')
  12. article_type = fields.Char(string='Article Type')
  13. article_source = fields.Char(string='Article Source')
  14. img_url = fields.Char(string='Image URL')
  15. keyword = fields.Char(string='Keyword')
  16. posted_date = fields.Char(string='Posted Date')
  17. create_time_ts = fields.Float(string='Creation Time TS')
  18. create_time = fields.Datetime(string='Creation Time')
  19. create_datetime = fields.Datetime(string='Creation Datetime')
  20. def _compute_context(self):
  21. context = ''
  22. for record in self:
  23. if record.context:
  24. if len(record.context) < 80:
  25. record.context_simple = record.context
  26. else:
  27. record.context_simple = f'{record.context[:80]}...'
  28. else:
  29. record.context_simple = context