from django.db import models
from base.models import BaseModel
from adminsortable.models import Sortable
from adminsortable.fields import SortableForeignKey
#from markitup.fields import MarkupField
from tinymce.models import HTMLField

class PageBase(BaseModel, Sortable):
    title = models.CharField(max_length=255)
    slug = models.SlugField(max_length=64)
    main_image = models.ImageField(upload_to='upload/images/pages/', blank=True, null=True)
    main_image_caption = models.CharField(max_length=512, blank=True)
    text = HTMLField(blank=True)
    template_name = "" #must be defined by subclass

    class Meta(Sortable.Meta):
        abstract = True

    def __unicode__(self):
        return self.title    

    def get_absolute_url(self):
        return "/%s/" % self.slug        

    def get_dict(self):
        return {
            'id': self.id,
            'slug': self.slug,
            'title': self.title,
            'main_image': self.main_image,
            'main_image_caption': self.main_image_caption,
            'text': self.text
        }

class ContentPage(PageBase):
    template_name = "contentpage.html"

    class Meta(Sortable.Meta):
        pass




# Create your models here.
