Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/mysite.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

275 changes: 161 additions & 114 deletions .idea/workspace.xml

Large diffs are not rendered by default.

Binary file added blog/__pycache__/__init__.cpython-34.pyc
Binary file not shown.
Binary file added blog/__pycache__/admin.cpython-34.pyc
Binary file not shown.
Binary file added blog/__pycache__/forms.cpython-34.pyc
Binary file not shown.
Binary file added blog/__pycache__/models.cpython-34.pyc
Binary file not shown.
Binary file added blog/__pycache__/urls.cpython-34.pyc
Binary file not shown.
Binary file added blog/__pycache__/views.cpython-34.pyc
Binary file not shown.
Binary file not shown.
Binary file added blog/migrations/__pycache__/__init__.cpython-34.pyc
Binary file not shown.
3 changes: 2 additions & 1 deletion blog/templates/blog/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@

<body>
<div class="page-header">

{% if user.is_authenticated %}
<a href="{% url 'post_new' %}" class="top-menu"><span class="glyphicon glyphicon-plus"></span></a>
<h1><a href="/">My Blog</a></h1>
{% endif %}

</div>
<div class="content container">
Expand Down
4 changes: 4 additions & 0 deletions blog/templates/blog/post_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
</div>

{% endif %}
{% if user.is_authenticated %}
<a class="btn btn-default" href="{% url 'post_edit' pk=post.pk %}"><span class="glyphicon glyphicon-pencil"></span></a
>
{% endif %}
<h1>{{ post.title }}</h1>
<p>{{ post.text|linebreaksbr }}</p>
</div>
Expand Down
7 changes: 4 additions & 3 deletions blog/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from . import views

urlpatterns = [
url(r'^$', views.post_list, name='post_list'),
url(r'^post/(?P<pk>\d+)/$', views.post_detail, name='post_detail'),
url(r'^post/new/$', views.post_new, name='post_new'),
url(r'^$', views.post_list, name='post_list'),
url(r'^post/(?P<pk>\d+)/$', views.post_detail, name='post_detail'),
url(r'^post/new/$', views.post_new, name='post_new'),
url(r'^post/(?P<pk>\d+)/edit/$',views.post_edit,name='post_edit'),
]
16 changes: 15 additions & 1 deletion blog/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,18 @@ def post_new(request):
return redirect('post_detail', pk=post.pk)
else:
form = PostForm()
return render(request, 'blog/post_edit.html', {'form': form})
return render(request, 'blog/post_edit.html', {'form': form})

def post_edit(request,pk):
post = get_object_or_404(Post, pk=pk)
if request.method == 'POST':
form = PostForm(request.POST,instance=post)
if form.is_valid():
post = form.save(commit=False)
post.author = request.user
post.published_date = timezone.now()
post.save()
return redirect('post_detail' , pk=post.pk)
else:
form =PostForm(instance= post)
return render(request,'blog/post_edit.html',{'form':form})
Binary file modified db.sqlite3
Binary file not shown.
Binary file added mysite/__pycache__/__init__.cpython-34.pyc
Binary file not shown.
Binary file added mysite/__pycache__/settings.cpython-34.pyc
Binary file not shown.
Binary file added mysite/__pycache__/urls.cpython-34.pyc
Binary file not shown.
Binary file added mysite/__pycache__/wsgi.cpython-34.pyc
Binary file not shown.