python
from django.db import models
from feincms.models import Base
class MyPage(Base):
title = models.CharField(max_length=100)
url = models.CharField(max_length=100)
class Meta:
verbose_name = 'My Page'
verbose_name_plural = 'My Pages'
MyPage.register_templates({
'title': 'Basic template',
'path': 'base.html',
'regions': (
('main', 'Main content area'),
('sidebar', 'Sidebar content area'),
),
})
MyPage.create_content_type(MyTextModel, regions=('main',))
MyPage.create_content_type(MyImageModel, regions=('main', 'sidebar'))
my_page = MyPage(title='My First Page', url='/my-first-page/')
my_text_module = MyPage.content_types['MyTextModel'].add_to_region(
my_page, 'main', {'content': 'Hello, world!'}
)
my_image_module = MyPage.content_types['MyImageModel'].add_to_region(
my_page, 'sidebar', {'image': 'path/to/image.jpg'}
)
html = my_page.render()
print(html)