Toggle navigation
Toggle navigation
This project
Loading...
Sign in
신은섭(Shin Eun Seop)
/
2018-1-d.cloud
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
10
Merge Requests
0
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
신은섭(Shin Eun Seop)
2018-05-17 11:04:34 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
7ed4068d04fc2585d8122e3a09f1d3f0a1a5181f
7ed4068d
1 parent
16ca03c3
add new_post, edit_post using forms
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
55 additions
and
2 deletions
dcloud/website/forms.py
dcloud/website/templates/website/base.html
dcloud/website/templates/website/post_detail.html
dcloud/website/templates/website/post_edit.html
dcloud/website/urls.py
dcloud/website/views.py
dcloud/website/forms.py
0 → 100644
View file @
7ed4068
from
django
import
forms
from
website.models
import
Post
class
PostForm
(
forms
.
ModelForm
):
class
Meta
:
model
=
Post
fields
=
(
'title'
,
'text'
)
\ No newline at end of file
dcloud/website/templates/website/base.html
View file @
7ed4068
...
...
@@ -9,6 +9,9 @@
</head>
<body>
<div
class=
"page-header"
>
{% if user.is_authenticated %}
<a
href=
"{% url 'post_new' %}"
class=
"top-menu"
><span
class=
"glyphicon glyphicon-plus"
></span></a>
{% endif %}
<h1><a
href=
"/"
>
Django Girls Blog
</a></h1>
</div>
<div
class=
"content container"
>
...
...
dcloud/website/templates/website/post_detail.html
View file @
7ed4068
{% extends 'website/base.html' %}
{% block content %}
<div
class=
"post"
>
{% if post.published_date %}
<div
class=
"date"
>
{{ post.published_date }}
</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>
...
...
dcloud/website/templates/website/post_edit.html
0 → 100644
View file @
7ed4068
{% extends 'website/base.html' %}
{% block content %}
<h1>
New post
</h1>
<form
method=
"POST"
class=
"post-form"
>
{% csrf_token %}
{{ form.as_p }}
<button
type=
"submit"
class=
"save btn btn-default"
>
Save
</button>
</form>
{% endblock %}
\ No newline at end of file
dcloud/website/urls.py
View file @
7ed4068
...
...
@@ -4,6 +4,8 @@ from website 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'^post/(?P<pk>\d+)/edit/$'
,
views
.
post_edit
,
name
=
'post_edit'
),
url
(
r'^files/'
,
views
.
file_list
,
name
=
'file_list'
),
]
\ No newline at end of file
...
...
dcloud/website/views.py
View file @
7ed4068
from
django.shortcuts
import
render
,
get_object_or_404
from
django.shortcuts
import
render
,
get_object_or_404
,
redirect
from
django.utils
import
timezone
from
website.models
import
Post
from
restful.models
import
File
from
website.forms
import
PostForm
...
...
@@ -17,3 +18,30 @@ def file_list(request):
def
post_detail
(
request
,
pk
):
post
=
get_object_or_404
(
Post
,
pk
=
pk
)
return
render
(
request
,
'website/post_detail.html'
,
{
'post'
:
post
})
def
post_new
(
request
):
if
request
.
method
==
"POST"
:
form
=
PostForm
(
request
.
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
()
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
})
\ No newline at end of file
...
...
Please
register
or
login
to post a comment