-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from django.db import models | ||
|
||
# Create your models here. | ||
|
||
class enterprise(models.Model): | ||
|
||
STATE_OWNED_ENTER = 1 | ||
COOPERATIVE_ENTER = 2 | ||
JOIN_VENTURE = 3 | ||
NATURE_CHOICES = ( | ||
(STATE_OWNED_ENTER,u'国有企业'), | ||
(COOPERATIVE_ENTER,'合作企业'), | ||
(JOIN_VENTURE,u'合资企业'), | ||
) | ||
enter_id = models.AutoField(primary_key=True,auto_created=True) | ||
enter_name = models.CharField(u'企业名称',max_length=50) | ||
register_time = models.DateField(u'注册时间') | ||
enter_address = models.CharField(u'注册地址',max_length=50) | ||
enter_nature = models.IntegerField(u'企业性质',default=STATE_OWNED_ENTER,choices=NATURE_CHOICES) | ||
|
||
class Meta: | ||
verbose_name = u'企业信息' | ||
verbose_name_plural = u'企业信息' | ||
|
||
|
||
def __unicode__(self): | ||
return self.enter_name | ||
|
||
|
||
class party(models.Model): | ||
party_id = models.AutoField(primary_key=True,auto_created=True) | ||
party_name = models.CharField(u'党支部名称',max_length=100) | ||
member_number = models.IntegerField(u'党员人数') | ||
contact_info = models.CharField(u'联系方式',max_length=300) | ||
|
||
class Meta: | ||
verbose_name = u'党支部信息' | ||
verbose_name_plural = u'党支部信息' | ||
|
||
|
||
def __unicode__(self): | ||
return self.party_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.shortcuts import render | ||
|
||
# Create your views here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
from django.contrib import admin | ||
from models import * | ||
|
||
# Register your models here. | ||
admin.site.register(Poll) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import requests | ||
import httplib | ||
import json | ||
data = {"username":"afadfa","password":"123456","email":"[email protected]"} | ||
headers = {"Content-Type":"application/json","Accept":"text/plain"} | ||
conn = httplib.HTTPConnection('127.0.0.1:8000') | ||
conn.request("POST","/rest/register/user/",json.dumps(data),headers) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.db import models | ||
|
||
# Create your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from rest_framework import serializers | ||
from django.contrib.auth.models import User | ||
from polls.models import Poll | ||
|
||
class UserSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = User | ||
fields = ('id','username','email') | ||
|
||
|
||
class PollSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Poll |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.conf.urls import url,patterns | ||
from rest import views | ||
|
||
urlpatterns = patterns('', | ||
url(r'^register/user/$',views.register_user), | ||
url(r'^list/polls/$',views.operate_poll) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from django.shortcuts import render | ||
from rest_framework.decorators import api_view | ||
from rest_framework import status | ||
from rest_framework.response import Response | ||
from rest_framework.parsers import JSONParser | ||
from serializers import * | ||
from django.views.decorators.csrf import csrf_exempt | ||
from polls.models import Poll | ||
import pdb | ||
|
||
# Create your views here. | ||
|
||
@csrf_exempt | ||
@api_view(['POST']) | ||
def register_user(request): | ||
print 'aaaa' | ||
print request.method | ||
print request.DATA | ||
print 'ddd' | ||
user = UserSerializer(data=request.DATA) | ||
if user.is_valid(): | ||
print 'valid' | ||
pdb.set_trace() | ||
u = User.objects.create_user(username=user.init_data['username'],email=user.init_data['email'],password=user.init_data['password']) | ||
u.save() | ||
return Response(user.data,status = status.HTTP_201_CREATED) | ||
else: | ||
pdb.set_trace() | ||
return Response(uesr.errors,status = status.HTTP_400_BAD_REQUEST) | ||
|
||
@api_view(['GET','POST']) | ||
def operate_poll(request): | ||
print 'aaaabbb' | ||
if request.method == 'GET': | ||
polls = Poll.objects.all() | ||
pserializered = PollSerializer(polls,many=True) | ||
return Response(pserializered.data) | ||
if request.method == 'POST': | ||
print 'method is:%s'%request.method | ||
print request.DATA | ||
p = PollSerializer(data=request.DATA) | ||
if p.is_valid(): | ||
p.save() | ||
return Response(p.data,status=status.HTTP_201_CREATED) | ||
else: | ||
return Response(p.errors,status = status.HTTP_400_BAD_REQUEST) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters