# Path: Blog/posts/models.py
# class Post(models.Model):
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, default=1)
#     title = models.CharField(max_length=120)
#     slug = models.SlugField(unique=True, null=True)
#     image = models.ImageField(null=True, blank=True,
#                               upload_to=upload_location,
#                               width_field="width_field",
#                               height_field="height_field")
#     width_field = models.IntegerField(default=0)
#     height_field = models.IntegerField(default=0)
#     content = models.TextField()
#     draft = models.BooleanField(default=False)
#     published = models.DateField(auto_now=False, auto_now_add=False)
#     updated = models.DateTimeField(auto_now=True, auto_now_add=False)  # auto_now triggered when model.save() called
#     timestamp = models.DateTimeField(auto_now=False, auto_now_add=True)  # auto_now_add triggered when object first created
#     num_chinese = models.IntegerField(default=0)
#     num_english = models.IntegerField(default=0)
#     objects = ActivePostManager()
# 
#     def __str__(self):  # __unicode__ for py2
#         return self.title
# 
#     def get_absolute_url(self):
#         return reverse("posts:detail", kwargs={"slug": self.slug})
# 
#     def get_api_url(self):
#         return reverse("posts-api:detail", kwargs={"slug": self.slug})
# 
#     def get_markdown(self):
#         content = self.content
#         return mark_safe(markdown(content))
# 
#     @property
#     def comments(self):
#         from comments.models import Comment
#         instance = self
#         return Comment.objects.filter_by_instance(instance)
# 
#     @property
#     def get_content_type(self):
#         instance = self
#         content_type = ContentType.objects.get_for_model(instance.__class__)
#         return content_type
# 
#     class Meta:
#         ordering= ['-published', '-updated']


from django import forms
from .models import Post
from pagedown.widgets import PagedownWidget
import datetime

class PostForm(forms.ModelForm):
    content = forms.CharField(widget=PagedownWidget(show_preview=False))
    published = forms.DateField(widget=forms.SelectDateWidget(years=range(1985, datetime.date.today().year+10)))
    class Meta:
        model = Post

# Path: Blog/posts/models.py
# class Post(models.Model):
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, default=1)
#     title = models.CharField(max_length=120)
#     slug = models.SlugField(unique=True, null=True)
#     image = models.ImageField(null=True, blank=True,
#                               upload_to=upload_location,
#                               width_field="width_field",
#                               height_field="height_field")
#     width_field = models.IntegerField(default=0)
#     height_field = models.IntegerField(default=0)
#     content = models.TextField()
#     draft = models.BooleanField(default=False)
#     published = models.DateField(auto_now=False, auto_now_add=False)
#     updated = models.DateTimeField(auto_now=True, auto_now_add=False)  # auto_now triggered when model.save() called
#     timestamp = models.DateTimeField(auto_now=False, auto_now_add=True)  # auto_now_add triggered when object first created
#     num_chinese = models.IntegerField(default=0)
#     num_english = models.IntegerField(default=0)
#     objects = ActivePostManager()
# 
#     def __str__(self):  # __unicode__ for py2
#         return self.title
# 
#     def get_absolute_url(self):
#         return reverse("posts:detail", kwargs={"slug": self.slug})
# 
#     def get_api_url(self):
#         return reverse("posts-api:detail", kwargs={"slug": self.slug})
# 
#     def get_markdown(self):
#         content = self.content
#         return mark_safe(markdown(content))
# 
#     @property
#     def comments(self):
#         from comments.models import Comment
#         instance = self
#         return Comment.objects.filter_by_instance(instance)
# 
#     @property
#     def get_content_type(self):
#         instance = self
#         content_type = ContentType.objects.get_for_model(instance.__class__)
#         return content_type
# 
#     class Meta:
#         ordering= ['-published', '-updated']


# Path: Blog/posts/forms.py
from django import forms
from .models import Post
from pagedown.widgets import PagedownWidget
import datetime


class PostForm(forms.ModelForm):
    content = forms.CharField(widget=PagedownWidget(show_preview=False))
    published = forms.DateField(widget=forms.SelectDateWidget(years=range(1985, datetime.date.today().year+10)))
    class Meta:
        model = Post

        fields = [