1
Fork 0
This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
theorangeone.net-legacy/project/common/models.py

40 lines
1.2 KiB
Python
Raw Permalink Normal View History

2016-11-24 21:44:08 +00:00
from wagtail.wagtailcore.models import Page
2016-11-28 21:56:44 +00:00
from django.db import models
from wagtail.wagtailadmin.edit_handlers import FieldPanel, MultiFieldPanel
from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
2016-12-15 22:00:42 +00:00
from wagtailmetadata.models import MetadataPageMixin
2016-12-24 23:10:21 +00:00
from bs4 import BeautifulSoup
2016-11-24 21:44:08 +00:00
2016-12-15 22:00:42 +00:00
class Entity(MetadataPageMixin, Page):
2016-11-25 20:23:02 +00:00
is_home = False
2016-11-28 21:56:44 +00:00
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
post_date = models.DateTimeField(null=True, blank=True)
promote_panels = [
MultiFieldPanel([
FieldPanel('slug'),
FieldPanel('seo_title'),
FieldPanel('post_date'),
FieldPanel('search_description'),
2016-12-24 19:48:49 +00:00
ImageChooserPanel('search_image'),
], 'Common page configuration'),
]
2016-12-20 19:05:29 +00:00
@property
def image(self):
return self.search_image
2016-12-20 19:03:58 +00:00
@property
def short_body(self):
2016-12-24 23:10:21 +00:00
body_words = BeautifulSoup(str(self.body)).get_text().split(' ')
return ' '.join(body_words[:30]) + '...' # limit to 30 words (ish)
2016-12-20 19:03:58 +00:00
def get_meta_description(self):
return self.search_description or self.short_body
2016-11-25 20:23:02 +00:00
class Meta:
abstract = True