| 12345678910111213141516171819202122232425262728293031323334 |
- # -*- coding: utf-8 -*-
- from odoo import models, fields, api
- class News(models.Model):
- _name = 'news.info'
- _description = 'News Info'
- _order = 'create_time_ts DESC'
- name = fields.Char(string='Title', required=True)
- context = fields.Text(string='Context')
- context_simple = fields.Char(string='Context Simple', compute='_compute_context')
- source_url = fields.Char(string='Source URL')
- link = fields.Char(string='Link')
- article_type = fields.Char(string='Article Type')
- article_source = fields.Char(string='Article Source')
- img_url = fields.Char(string='Image URL')
- keyword = fields.Char(string='Keyword')
- posted_date = fields.Char(string='Posted Date')
- create_time_ts = fields.Float(string='Creation Time TS')
- create_time = fields.Datetime(string='Creation Time')
- create_datetime = fields.Datetime(string='Creation Datetime')
- def _compute_context(self):
- context = ''
- for record in self:
- if record.context:
- if len(record.context) < 80:
- record.context_simple = record.context
- else:
- record.context_simple = f'{record.context[:80]}...'
- else:
- record.context_simple = context
|