class PostForm(forms.ModelForm): | class PostForm(forms.ModelForm): | ||||
class Meta: | class Meta: | ||||
model = Post | model = Post | ||||
fields = ('title', 'text', 'published_date', 'tags') | |||||
fields = ('title', 'text', 'published_date','tags') | |||||
class NewTagForm(forms.ModelForm): | class NewTagForm(forms.ModelForm): | ||||
m_tags = TagField() | m_tags = TagField() |
from taggit.managers import TaggableManager | from taggit.managers import TaggableManager | ||||
class CustomUser(models.Model): | class CustomUser(models.Model): | ||||
user = models.OneToOneField(User, null = True, on_delete=models.CASCADE) | |||||
user = models.OneToOneField('auth.User', null = True, on_delete=models.CASCADE) | |||||
tags = TaggableManager() | tags = TaggableManager() | ||||
url(r'^drafts/$', views.post_draft_list, name='post_draft_list'), | url(r'^drafts/$', views.post_draft_list, name='post_draft_list'), | ||||
url(r'^post/(?P<pk>\d+)/publish/$', views.post_publish, name='post_publish'), | url(r'^post/(?P<pk>\d+)/publish/$', views.post_publish, name='post_publish'), | ||||
url(r'^post/(?P<pk>\d+)/remove/$', views.post_remove, name='post_remove'), | url(r'^post/(?P<pk>\d+)/remove/$', views.post_remove, name='post_remove'), | ||||
url(r'^tags/', include('taggit_templatetags2.urls')), | |||||
url(r'^tags/', include('taggit_templatetags2.urls')), | |||||
] | ] | ||||
post = form.save(commit=False) | post = form.save(commit=False) | ||||
post.author = request.user | post.author = request.user | ||||
post.save() | post.save() | ||||
form.save_m2m() | |||||
return redirect('post_detail', pk=post.pk) | return redirect('post_detail', pk=post.pk) | ||||
else: | else: | ||||
form = PostForm(instance=post) | form = PostForm(instance=post) |