# Path: boards/models.py
# class Post(models.Model):
#     message = models.TextField(max_length=4000)
#     topic = models.ForeignKey(Topic, related_name='posts')
#     created_at = models.DateTimeField(auto_now_add=True)
#     updated_at = models.DateTimeField(null=True)
#     created_by = models.ForeignKey(User, related_name='posts')
#     updated_by = models.ForeignKey(User, null=True, related_name='+')
# 
#     def __str__(self):
#         truncated_message = Truncator(self.message)
#         return truncated_message.chars(30)
# 
#     def get_message_as_markdown(self):
#         return mark_safe(markdown(self.message, safe_mode='escape'))
# 
# class Topic(models.Model):
#     subject = models.CharField(max_length=255)
#     last_updated = models.DateTimeField(auto_now_add=True)
#     board = models.ForeignKey(Board, related_name='topics')
#     starter = models.ForeignKey(User, related_name='topics')
#     views = models.PositiveIntegerField(default=0)
# 
#     def __str__(self):
#         return self.subject
# 
#     def get_page_count(self):
#         count = self.posts.count()
#         pages = count / 20
#         return math.ceil(pages)
# 
#     def has_many_pages(self, count=None):
#         if count is None:
#             count = self.get_page_count()
#         return count > 6
# 
#     def get_page_range(self):
#         count = self.get_page_count()
#         if self.has_many_pages(count):
#             return range(1, 5)
#         return range(1, count + 1)
# 
#     def get_last_ten_posts(self):
#         return self.posts.order_by('-created_at')[:10]


from django import forms
from .models import Post, Topic



class NewTopicForm(forms.ModelForm):
    message = forms.CharField(
        widget=forms.Textarea(
            attrs={'rows': 5, 'placeholder': 'What is in your mind?'}
        ),
        max_length=4000,
        help_text='The max length of the text is 4000.'
    )

    class Meta:
        model = Topic
        fields = ['subject', 'message']


class PostForm(forms.ModelForm):
    class Meta:
        model = Post

# Path: boards/models.py
# class Post(models.Model):
#     message = models.TextField(max_length=4000)
#     topic = models.ForeignKey(Topic, related_name='posts')
#     created_at = models.DateTimeField(auto_now_add=True)
#     updated_at = models.DateTimeField(null=True)
#     created_by = models.ForeignKey(User, related_name='posts')
#     updated_by = models.ForeignKey(User, null=True, related_name='+')
# 
#     def __str__(self):
#         truncated_message = Truncator(self.message)
#         return truncated_message.chars(30)
# 
#     def get_message_as_markdown(self):
#         return mark_safe(markdown(self.message, safe_mode='escape'))
# 
# class Topic(models.Model):
#     subject = models.CharField(max_length=255)
#     last_updated = models.DateTimeField(auto_now_add=True)
#     board = models.ForeignKey(Board, related_name='topics')
#     starter = models.ForeignKey(User, related_name='topics')
#     views = models.PositiveIntegerField(default=0)
# 
#     def __str__(self):
#         return self.subject
# 
#     def get_page_count(self):
#         count = self.posts.count()
#         pages = count / 20
#         return math.ceil(pages)
# 
#     def has_many_pages(self, count=None):
#         if count is None:
#             count = self.get_page_count()
#         return count > 6
# 
#     def get_page_range(self):
#         count = self.get_page_count()
#         if self.has_many_pages(count):
#             return range(1, 5)
#         return range(1, count + 1)
# 
#     def get_last_ten_posts(self):
#         return self.posts.order_by('-created_at')[:10]


# Path: boards/forms.py
from django import forms
from .models import Post, Topic




class NewTopicForm(forms.ModelForm):
    message = forms.CharField(
        widget=forms.Textarea(
            attrs={'rows': 5, 'placeholder': 'What is in your mind?'}
        ),
        max_length=4000,
        help_text='The max length of the text is 4000.'
    )

    class Meta:
        model = Topic
        fields = ['subject', 'message']


class PostForm(forms.ModelForm):
    class Meta:
        model = Post

        fields = ['message', ]