Skip to content

Commit 7fd19fb

Browse files
committed
first stage duplicate of the application
1 parent 62adca6 commit 7fd19fb

File tree

15 files changed

+270
-0
lines changed

15 files changed

+270
-0
lines changed
156 KB
Binary file not shown.
Lines changed: 10 additions & 0 deletions
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", "mysite.settings")
7+
8+
from django.core.management import execute_from_command_line
9+
10+
execute_from_command_line(sys.argv)

resources/session08/mysite_stage_1/myblog/__init__.py

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.contrib import admin
2+
from myblog.models import Post, Category
3+
4+
5+
admin.site.register(Post)
6+
admin.site.register(Category)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[
2+
{
3+
"pk": 1,
4+
"model": "auth.user",
5+
"fields": {
6+
"username": "admin",
7+
"first_name": "Mr.",
8+
"last_name": "Administrator",
9+
"is_active": true,
10+
"is_superuser": true,
11+
"is_staff": true,
12+
"last_login": "2013-05-24T05:35:58.628Z",
13+
"groups": [],
14+
"user_permissions": [],
15+
"password": "pbkdf2_sha256$10000$1rQazFNdOfFt$6aw/uIrv2uASkZ7moXMTajSN+ySYuowBnbP6ILNQntE=",
16+
"email": "[email protected]",
17+
"date_joined": "2013-05-24T05:35:58.628Z"
18+
}
19+
},
20+
{
21+
"pk": 2,
22+
"model": "auth.user",
23+
"fields": {
24+
"username": "noname",
25+
"first_name": "",
26+
"last_name": "",
27+
"is_active": true,
28+
"is_superuser": true,
29+
"is_staff": true,
30+
"last_login": "2013-05-24T05:35:58.628Z",
31+
"groups": [],
32+
"user_permissions": [],
33+
"password": "pbkdf2_sha256$10000$1rQazFNdOfFt$6aw/uIrv2uASkZ7moXMTajSN+ySYuowBnbP6ILNQntE=",
34+
"email": "[email protected]",
35+
"date_joined": "2013-05-24T05:35:58.628Z"
36+
}
37+
}
38+
]
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
4+
from django.db import models, migrations
5+
from django.conf import settings
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
12+
]
13+
14+
operations = [
15+
migrations.CreateModel(
16+
name='Post',
17+
fields=[
18+
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
19+
('title', models.CharField(max_length=128)),
20+
('text', models.TextField(blank=True)),
21+
('created_date', models.DateTimeField(auto_now_add=True)),
22+
('modified_date', models.DateTimeField(auto_now=True)),
23+
('published_date', models.DateTimeField(null=True, blank=True)),
24+
('author', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
25+
],
26+
options={
27+
},
28+
bases=(models.Model,),
29+
),
30+
]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
('myblog', '0001_initial'),
11+
]
12+
13+
operations = [
14+
migrations.CreateModel(
15+
name='Category',
16+
fields=[
17+
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
18+
('name', models.CharField(max_length=128)),
19+
('description', models.TextField(blank=True)),
20+
('posts', models.ManyToManyField(related_name='categories', null=True, to='myblog.Post', blank=True)),
21+
],
22+
options={
23+
},
24+
bases=(models.Model,),
25+
),
26+
]

resources/session08/mysite_stage_1/myblog/migrations/__init__.py

Whitespace-only changes.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from django.db import models
2+
from django.contrib.auth.models import User
3+
4+
5+
class Post(models.Model):
6+
title = models.CharField(max_length=128)
7+
text = models.TextField(blank=True)
8+
author = models.ForeignKey(User)
9+
created_date = models.DateTimeField(auto_now_add=True)
10+
modified_date = models.DateTimeField(auto_now=True)
11+
published_date = models.DateTimeField(blank=True, null=True)
12+
13+
def __unicode__(self):
14+
return self.title
15+
16+
17+
class Category(models.Model):
18+
name = models.CharField(max_length=128)
19+
description = models.TextField(blank=True)
20+
posts = models.ManyToManyField(Post, blank=True, null=True,
21+
related_name='categories')
22+
23+
def __unicode__(self):
24+
return self.name
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from django.test import TestCase
2+
from django.contrib.auth.models import User
3+
from myblog.models import Post, Category
4+
5+
6+
class PostTestCase(TestCase):
7+
fixtures = ['myblog_test_fixture.json', ]
8+
9+
def setUp(self):
10+
self.user = User.objects.get(pk=1)
11+
12+
def test_unicode(self):
13+
expected = "This is a title"
14+
p1 = Post(title=expected)
15+
actual = unicode(p1)
16+
self.assertEqual(expected, actual)
17+
18+
19+
class CategoryTestCase(TestCase):
20+
21+
def test_unicode(self):
22+
expected = "A Category"
23+
c1 = Category(name=expected)
24+
actual = unicode(c1)
25+
self.assertEqual(expected, actual)

0 commit comments

Comments
 (0)