# Path: bamboo/models.py
# class Post(models.Model):
#     # author = models.ForeignKey('auth.User', null=True)
#     writer = models.CharField(max_length=100)
#     title = models.CharField(max_length=200)
#     text = models.TextField()
# #    created_date = models.DateTimeField(default=timezone.now)
#     published_date = models.DateTimeField(blank=True, null=True)
#     category = models.ForeignKey(Category, default=1, blank=True)
#     post_password = models.CharField(verbose_name=u'password', max_length=100, default='', help_text="글을 수정하거나 지울 때 사용할 비밀번호를 적어주세요")
# 
#     def publish(self):
#         self.published_date = timezone.now()
#         self.save()
# 
#     def __str__(self):
#         return self.title
# 
# class Category(models.Model):
# #    class Meta:
# #        ordering = ['name']
#     name = models.CharField(verbose_name=u'이름', max_length=50)
#     slug = models.SlugField(unique=True, null=True, blank=True)
#     description = models.TextField(verbose_name=u'말머리 설명', blank=True)
# 
#     def __str__(self):
#         return self.name
# 
# Path: bamboo/forms.py
# class PostForm(forms.ModelForm):
#     post_password = forms.CharField(widget=forms.PasswordInput)
# 
#     class Meta:
#         model = Post
#         fields = ('category', 'writer', 'post_password', 'title', 'text', )
# 
# class CommentForm(forms.ModelForm):
# 
#     class Meta:
#         model = Comment
#         fields = ('author', 'text', )
# 
# class PasswordCheckForm(forms.Form):
#     password = forms.CharField(widget=forms.PasswordInput)


from django.shortcuts import render, redirect, get_object_or_404
from django.utils import timezone
from .models import Post, Category
from .forms import PostForm, CommentForm, PasswordCheckForm



# Create your views here.
def post_list(request):
    posts = Post.objects.filter().order_by('-published_date')
    categories = Category.objects.filter().order_by('name')
    template_name = 'bamboo/post_list.html'
    context_data = {'posts': posts, 'categories': categories}
    return render(request, template_name, context_data)


def post_list_by_tag(request, pk):
    posts = Post.objects.filter(category=pk).order_by('-published_date')

# Path: bamboo/models.py
# class Post(models.Model):
#     # author = models.ForeignKey('auth.User', null=True)
#     writer = models.CharField(max_length=100)
#     title = models.CharField(max_length=200)
#     text = models.TextField()
# #    created_date = models.DateTimeField(default=timezone.now)
#     published_date = models.DateTimeField(blank=True, null=True)
#     category = models.ForeignKey(Category, default=1, blank=True)
#     post_password = models.CharField(verbose_name=u'password', max_length=100, default='', help_text="글을 수정하거나 지울 때 사용할 비밀번호를 적어주세요")
# 
#     def publish(self):
#         self.published_date = timezone.now()
#         self.save()
# 
#     def __str__(self):
#         return self.title
# 
# class Category(models.Model):
# #    class Meta:
# #        ordering = ['name']
#     name = models.CharField(verbose_name=u'이름', max_length=50)
#     slug = models.SlugField(unique=True, null=True, blank=True)
#     description = models.TextField(verbose_name=u'말머리 설명', blank=True)
# 
#     def __str__(self):
#         return self.name
# 
# Path: bamboo/forms.py
# class PostForm(forms.ModelForm):
#     post_password = forms.CharField(widget=forms.PasswordInput)
# 
#     class Meta:
#         model = Post
#         fields = ('category', 'writer', 'post_password', 'title', 'text', )
# 
# class CommentForm(forms.ModelForm):
# 
#     class Meta:
#         model = Comment
#         fields = ('author', 'text', )
# 
# class PasswordCheckForm(forms.Form):
#     password = forms.CharField(widget=forms.PasswordInput)


# Path: bamboo/views.py
from django.shortcuts import render, redirect, get_object_or_404
from django.utils import timezone
from .models import Post, Category
from .forms import PostForm, CommentForm, PasswordCheckForm



# Create your views here.
def post_list(request):
    posts = Post.objects.filter().order_by('-published_date')
    categories = Category.objects.filter().order_by('name')
    template_name = 'bamboo/post_list.html'
    context_data = {'posts': posts, 'categories': categories}
    return render(request, template_name, context_data)


def post_list_by_tag(request, pk):
    posts = Post.objects.filter(category=pk).order_by('-published_date')

    categories = Category.objects.filter().order_by('name')
