Skip to content

Commit b32eb7e

Browse files
committed
django
django
1 parent a54447d commit b32eb7e

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

HelloWorld/TestModel/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Meta:
4343
class ArticleForm(forms.ModelForm):
4444
class Meta:
4545
model = article
46-
exclude = ('create_date',)
46+
exclude = ('create_date','publish_date')
4747

4848

4949
if __name__ == '__main__':

HelloWorld/TestModel/view.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# -*- coding: utf-8 -*-
22
#from django.http import HttpResponse
3+
4+
from datetime import datetime
35
from django.shortcuts import render
46
from .models import Test,article
57

@@ -53,7 +55,14 @@ def hello(request):
5355
# return HttpResponseRedirect('/hello/list/')
5456

5557
def add_article_new(requset):
56-
pass
58+
if request.methodo == 'POST':
59+
form = ArticleForm(request.POST)
60+
if form.is_valid():
61+
post = form.save(commit = False)
62+
post.create_date = datetime.now()
63+
post.publish_date = datetime.now()
64+
post.save()
65+
return HttpResponseRedirect('/hello/list/')
5766

5867

5968

0 commit comments

Comments
 (0)