# -*- coding: utf-8 -*- from odoo import models, fields, api from datetime import datetime class ChennoraBlogPost(models.Model): _name = 'chennora.blog.post' _description = 'Chennora Blog Post' _order = 'date desc, id desc' title = fields.Char(string='Title', required=True) slug = fields.Char(string='URL Slug', required=True, help="Used in the URL e.g. 'my-first-post'") category = fields.Char(string='Category', default='Restaurant Spotlight') excerpt = fields.Text(string='Excerpt', help="Short summary for the blog card") content = fields.Html(string='Content', sanitize=True) image = fields.Char(string='Image URL', default='/dine360_theme_chennora/static/src/img/blog-1.png') date = fields.Date(string='Publish Date', default=fields.Date.context_today) active = fields.Boolean(default=True) # Computed fields for the blog card date badge day = fields.Char(compute='_compute_date_parts', store=True) month = fields.Char(compute='_compute_date_parts', store=True) _sql_constraints = [ ('slug_unique', 'unique(slug)', 'The slug must be unique!') ] @api.depends('date') def _compute_date_parts(self): for record in self: if record.date: dt = fields.Date.from_string(record.date) record.day = dt.strftime('%d') record.month = dt.strftime('%b').upper() else: record.day = '' record.month = ''