models. Model):=models. IntegerField (u « Порядкоий номер », blank=True, null=True)=models. CharField (u « Заголовок », max_length=64, blank=True, null=True)=models. CharField (u « Автор », max_length=200, blank=True)=FileBrowseField (u « Фото », max_length=200 , directory= images/ blog / raquo ;, format= image raquo ;, null=True, blank=True) _of_publication=models. DateTimeField (verbose_name=u Дата публікації новини raquo ;, blank= True, null=True, default=datetime.datetime.now)=SplitField (u Текст raquo ;, blank=True)=models. ManyToManyField (Tags, verbose_name=u Теги raquo ;, blank=True) __ unicode __ (self): u % S % (self.zagol,) Meta: _name=u Блог »_name_plural=u Блог » Comment (models. Model):=models. ForeignKey (Blog, verbose_name=u Від якогось блогу raquo ;, related_name= link_blog raquo ;, blank=True, null=True) _name=models. CharField (u « Автор », max_length=120, blank=True)=models. TextField (u Коментар raquo ;, blank=True) _date=models. DateTimeField (u Дата публікації raquo ;, default=datetime.datetime.now, blank=True) _comment=models. BooleanField (u Допущена адміністратором raquo ;, default=False, blank=True) __ unicode __ (self): self.author_namecount_comment ( self): Comment.objects.filter (article=self.article) .count () Meta: _name=u Коментар »_name_plural=u Коментарі »=[ pub_date raquo ;,]
Файл admin.py для докладання blog:
# - * - encoding: utf -8 - * - django.contrib import admin.models import Blog, Comment, TagsBlogAdmin (admin. ModelAdmin): _ display=( number raquo ;, zagol ,) _ display_links=( number raquo ;, zagol ,) _ filter=() _fields=()=( number ,) _ hierarchy= laquo ; date_of_publication TagsAdmin (admin. ModelAdmin): _ display=( number raquo ;, name ,) _ display_links=( number raquo ;, name ,) _ filter=() _fields=()=( name raquo ;,)
CommentAdmin (admin. ModelAdmin): _ display=( pub_date raquo ;, laquo;author_nameraquo;,)_fields=(laquo;textraquo;,)_filter=(laquo;author_nameraquo;,)_hierarchy=laquo;pub_dateraquo;
. site.register (Blog, BlogAdmin) .site.register (Tags, TagsAdmin) .site.register (Comment, CommentAdmin)
Файл forms.py для докладання blog:
# - * - coding: utf -8 - * - django import formsregistration.forms import RegistrationFormUniqueEmaildjango.core.mail import send_mail.models import Blog
RegistrationFormProfile (RegistrationFormUniqueEmail):=forms. CharField (label= Робота )
BlogForm (forms. Form):=forms. CharField (max_length=150)=forms. EmailField ()=forms. CharField (widget=forms. Textarea) send_email (self, subject, message, from_email, recipient_list=[ viktori2000 @ qip ], fail_silently=False): send_mail (subject, message, from_email, recipient_list, fail_silently)
Файл views.py для докладання blog:
# - * - coding: utf -8 - * - django.views.generic import ListView, DetailView, TemplateView.models import Blog, Tags, Commentdjango.contrib.auth.models import Userdjango.views.generic.edit import FormView, CreateView, UpdateViewdjango.forms import ModelFormdjango import formsdjango.db.models import Qdjango.contrib.auth.models import Userdatetime.forms import BlogFormdjango.views.generic.edit import CreateViewdjango.views.generic.dates import MonthArchiveViewprofile.models import Profiledjango.shortcuts import redirectdjango.core.urlresolvers import reverseCreateNews (CreateView):=Blog=[ number raquo ;, zagol raquo ;, author raquo ;, image raquo ;, date_of_publication raquo ;, text raquo ;, tags ] get_context_data (self, ** kwargs): self.request.user.is_authenticated () and Profile.objects.get (pk=self.request.user.id) .party == True:=super (CreateNews, self) .get_context_data (** kwargs) [ object ]=Profile.objects.get (pk=self.request.user.id) context
class BlogList (ListView):=Blog_object_name=«