Skip to content

Commit

Permalink
Version 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
DevRoss committed Mar 8, 2017
1 parent 774fa22 commit 6409bd0
Show file tree
Hide file tree
Showing 20 changed files with 27 additions and 102 deletions.
Binary file modified Anonymous_message/__pycache__/settings.cpython-35.pyc
Binary file not shown.
8 changes: 5 additions & 3 deletions Anonymous_message/settings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# coding: utf-8

"""
Django settings for Anonymous_message project.
Expand Down Expand Up @@ -26,7 +28,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

ALLOWED_HOSTS = ['127.0.0.1']
ALLOWED_HOSTS = ['127.0.0.1', '*']

# Application definition

Expand All @@ -45,7 +47,7 @@
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
# 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
Expand Down Expand Up @@ -134,5 +136,5 @@

REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
'PAGE_SIZE': 20
'PAGE_SIZE': 8
}
Binary file removed db.sqlite3
Binary file not shown.
Binary file modified website/__pycache__/__init__.cpython-35.pyc
Binary file not shown.
Binary file modified website/__pycache__/admin.cpython-35.pyc
Binary file not shown.
Binary file modified website/__pycache__/models.cpython-35.pyc
Binary file not shown.
Binary file modified website/__pycache__/serializer.cpython-35.pyc
Binary file not shown.
Binary file modified website/__pycache__/urls.cpython-35.pyc
Binary file not shown.
Binary file modified website/__pycache__/views.cpython-35.pyc
Binary file not shown.
25 changes: 0 additions & 25 deletions website/migrations/0001_initial.py

This file was deleted.

19 changes: 0 additions & 19 deletions website/migrations/0002_remove_messages_ip.py

This file was deleted.

31 changes: 0 additions & 31 deletions website/migrations/0003_auto_20170305_2000.py

This file was deleted.

21 changes: 0 additions & 21 deletions website/migrations/0004_auto_20170305_2006.py

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file modified website/migrations/__pycache__/__init__.cpython-35.pyc
Binary file not shown.
3 changes: 2 additions & 1 deletion website/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.db import models
from django.template.defaultfilters import default

from website.extend_function import getIPFromDJangoRequest

# from website.extend_function import getIPFromDJangoRequest


# Create your models here.
Expand Down
7 changes: 6 additions & 1 deletion website/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ def get_time(self, obj):

# 发表留言
class PostMessageSerializer(serializers.ModelSerializer):
time = serializers.SerializerMethodField()

class Meta:
model = Messages
fields = ('content',)
fields = ('content', 'time')

def get_time(self, obj):
return dateformat.format(obj.time, 'U')
4 changes: 3 additions & 1 deletion website/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from django.conf.urls import url
from website.views import (GetMessageList,
PostMessage)
PostMessage,
PostMessageDev)

urlpatterns = [
url(r'messagelist/$', GetMessageList.as_view()),
url(r'postmessage/$', PostMessage.as_view()),
url(r'postmessagedev/$', PostMessageDev.as_view()),
]
11 changes: 11 additions & 0 deletions website/views.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
# from django.shortcuts import render
from rest_framework import generics
# from rest_framework.views import APIView
from rest_framework.filters import OrderingFilter

from website.models import Messages
from website.serializer import (GetMessageSerializer,
PostMessageSerializer)
from rest_framework import parsers
from rest_framework import filters


# Create your views here.

class GetMessageList(generics.ListAPIView):
queryset = Messages.objects.all()
serializer_class = GetMessageSerializer
filter_backends = (filters.OrderingFilter, filters.SearchFilter)
search_fields = ('content',)
ordering = ('-time',)


class PostMessage(generics.CreateAPIView):
serializer_class = PostMessageSerializer
parser_classes = (parsers.JSONParser,)


class PostMessageDev(generics.CreateAPIView):
serializer_class = PostMessageSerializer
parser_classes = (parsers.FormParser,)

0 comments on commit 6409bd0

Please sign in to comment.