Skip to content
This repository was archived by the owner on Mar 5, 2019. It is now read-only.

Commit 9b2481a

Browse files
committed
First serializers import
1 parent 90455a6 commit 9b2481a

18 files changed

+244
-0
lines changed

.gitignore

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
*.py[co]
2+
3+
# Packages
4+
*.egg
5+
*.egg-info
6+
dist
7+
build
8+
eggs
9+
parts
10+
bin
11+
develop-eggs
12+
.installed.cfg
13+
scratch
14+
env
15+
venv*
16+
17+
# Installer logs
18+
pip-log.txt
19+
20+
# Unit test / coverage reports
21+
.coverage
22+
.tox
23+
24+
.DS_Store
25+
26+
# Sphinx
27+
docs/tmp
28+
docs/_build
29+
cover
30+
31+
# PyCharm/IntelliJ
32+
.idea
33+
34+
#htmlcov
35+
*htmlcov*
36+
37+
#db
38+
*.sqlite3

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
# Django REST Framework Tutorial
2+
3+
## Part 1 - Serializers

coffeecounter/api/__init__.py

Whitespace-only changes.

coffeecounter/api/admin.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
4+
from django.db import models, migrations
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
]
11+
12+
operations = [
13+
migrations.CreateModel(
14+
name='Badge',
15+
fields=[
16+
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
17+
('title', models.CharField(max_length=100)),
18+
('description', models.CharField(max_length=100)),
19+
],
20+
options={
21+
},
22+
bases=(models.Model,),
23+
),
24+
]

coffeecounter/api/migrations/__init__.py

Whitespace-only changes.

coffeecounter/api/models.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from django.db import models
2+
from django.contrib.auth.models import User
3+
4+
5+
class Badge(models.Model):
6+
title = models.CharField(max_length=100, blank=False, null=False)
7+
description = models.CharField(max_length=100, blank=False, null=False)

coffeecounter/api/serializers.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from .models import Badge
2+
from rest_framework import serializers
3+
4+
5+
class BadgeSerializer(serializers.ModelSerializer):
6+
class Meta:
7+
model = Badge
8+
fields = ('id', 'title', 'description')

coffeecounter/api/tests/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from django.test import TestCase
2+
from api.serializers import BadgeSerializer
3+
4+
class TestSerializers(TestCase):
5+
6+
def setUp(self):
7+
pass
8+
9+
def tearDown(self):
10+
pass
11+
12+
def test_badge_serializer_valid(self):
13+
data = {'pk': 2, 'title': u'Coffee tester', 'description': u'<3 @ 180bpm'}
14+
serializer = BadgeSerializer(data=data)
15+
self.assertTrue(serializer.is_valid())
16+
17+
def test_badge_serializer_not_valid(self):
18+
data = {'pk': 2, 'tile': u'Coffee tester', 'description': u'<3 @ 180bpm'}
19+
serializer = BadgeSerializer(data=data)
20+
self.assertFalse(serializer.is_valid())

coffeecounter/api/views.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.shortcuts import render
2+
3+
# Create your views here.

coffeecounter/coffeecounter/__init__.py

Whitespace-only changes.
+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
"""
2+
Django settings for coffeecounter project.
3+
4+
For more information on this file, see
5+
https://docs.djangoproject.com/en/1.7/topics/settings/
6+
7+
For the full list of settings and their values, see
8+
https://docs.djangoproject.com/en/1.7/ref/settings/
9+
"""
10+
11+
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
12+
import os
13+
import sys
14+
15+
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
16+
17+
18+
# Quick-start development settings - unsuitable for production
19+
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
20+
21+
# SECURITY WARNING: keep the secret key used in production secret!
22+
SECRET_KEY = '-l0h@c2i6+p#2+t5urtrml#43_a8pso7+###64yb6lt$%+wj6x'
23+
24+
# SECURITY WARNING: don't run with debug turned on in production!
25+
DEBUG = True
26+
27+
TEMPLATE_DEBUG = True
28+
29+
ALLOWED_HOSTS = []
30+
31+
32+
# Application definition
33+
34+
INSTALLED_APPS = (
35+
'django.contrib.admin',
36+
'django.contrib.auth',
37+
'django.contrib.contenttypes',
38+
'django.contrib.sessions',
39+
'django.contrib.messages',
40+
'django.contrib.staticfiles',
41+
'rest_framework',
42+
'api'
43+
)
44+
45+
MIDDLEWARE_CLASSES = (
46+
'django.contrib.sessions.middleware.SessionMiddleware',
47+
'django.middleware.common.CommonMiddleware',
48+
'django.middleware.csrf.CsrfViewMiddleware',
49+
'django.contrib.auth.middleware.AuthenticationMiddleware',
50+
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
51+
'django.contrib.messages.middleware.MessageMiddleware',
52+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
53+
)
54+
55+
ROOT_URLCONF = 'coffeecounter.urls'
56+
57+
WSGI_APPLICATION = 'coffeecounter.wsgi.application'
58+
59+
60+
# Database
61+
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
62+
63+
DATABASES = {
64+
'default': {
65+
'ENGINE': 'django.db.backends.sqlite3',
66+
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
67+
}
68+
}
69+
70+
if 'test' in sys.argv:
71+
DATABASES = {
72+
'default': {
73+
'ENGINE': 'django.db.backends.sqlite3',
74+
'NAME': os.path.join(os.path.dirname(__file__), 'test.db'),
75+
'TEST_NAME': os.path.join(os.path.dirname(__file__), 'test.db'),
76+
}
77+
}
78+
79+
# Internationalization
80+
# https://docs.djangoproject.com/en/1.7/topics/i18n/
81+
82+
LANGUAGE_CODE = 'en-us'
83+
84+
TIME_ZONE = 'UTC'
85+
86+
USE_I18N = True
87+
88+
USE_L10N = True
89+
90+
USE_TZ = True
91+
92+
93+
# Static files (CSS, JavaScript, Images)
94+
# https://docs.djangoproject.com/en/1.7/howto/static-files/
95+
96+
STATIC_URL = '/static/'

coffeecounter/coffeecounter/urls.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from django.conf.urls import patterns, include, url
2+
from django.contrib import admin
3+
4+
urlpatterns = patterns('',
5+
# Examples:
6+
# url(r'^$', 'coffeecounter.views.home', name='home'),
7+
# url(r'^blog/', include('blog.urls')),
8+
9+
url(r'^admin/', include(admin.site.urls)),
10+
)

coffeecounter/coffeecounter/wsgi.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""
2+
WSGI config for coffeecounter project.
3+
4+
It exposes the WSGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/
8+
"""
9+
10+
import os
11+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "coffeecounter.settings")
12+
13+
from django.core.wsgi import get_wsgi_application
14+
application = get_wsgi_application()

coffeecounter/manage.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env python
2+
import os
3+
import sys
4+
5+
if __name__ == "__main__":
6+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "coffeecounter.settings")
7+
8+
from django.core.management import execute_from_command_line
9+
10+
execute_from_command_line(sys.argv)

coffeecounter/requirements-devel.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-r requirements.txt
2+
3+
py==1.4.26
4+
tox==1.9.0
5+
virtualenv==12.0.7

coffeecounter/requirements.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Django==1.7.5
2+
argparse==1.2.1
3+
djangorestframework==3.0.5
4+
wsgiref==0.1.2

0 commit comments

Comments
 (0)