From 5797c7e71613e9e7920627066d0f55cde541692a Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Mon, 3 Oct 2016 21:36:14 +0100 Subject: [PATCH] Added admin --- .gitignore | 3 +++ blog/__init__.py | 0 blog/admin.py | 4 ++++ blog/apps.py | 5 +++++ blog/migrations/0001_initial.py | 31 +++++++++++++++++++++++++++++ blog/migrations/__init__.py | 0 blog/models.py | 16 +++++++++++++++ blog/tests.py | 3 +++ blog/views.py | 3 +++ mysite/django-girls.sublime-project | 6 ++++++ mysite/settings.py | 1 + 11 files changed, 72 insertions(+) create mode 100644 blog/__init__.py create mode 100644 blog/admin.py create mode 100644 blog/apps.py create mode 100644 blog/migrations/0001_initial.py create mode 100644 blog/migrations/__init__.py create mode 100644 blog/models.py create mode 100644 blog/tests.py create mode 100644 blog/views.py diff --git a/.gitignore b/.gitignore index 0546add..16c050f 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,6 @@ nosetests.xml # Logs *.log + +# Databases +*sqlite3 diff --git a/blog/__init__.py b/blog/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/blog/admin.py b/blog/admin.py new file mode 100644 index 0000000..47f03fd --- /dev/null +++ b/blog/admin.py @@ -0,0 +1,4 @@ +from django.contrib import admin +from .models import Post + +admin.site.register(Post) diff --git a/blog/apps.py b/blog/apps.py new file mode 100644 index 0000000..7930587 --- /dev/null +++ b/blog/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class BlogConfig(AppConfig): + name = 'blog' diff --git a/blog/migrations/0001_initial.py b/blog/migrations/0001_initial.py new file mode 100644 index 0000000..91bc243 --- /dev/null +++ b/blog/migrations/0001_initial.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.2 on 2016-10-03 10:57 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion +import django.utils.timezone + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='Post', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=300)), + ('text', models.TextField()), + ('created_date', models.DateTimeField(default=django.utils.timezone.now)), + ('published_date', models.DateTimeField(blank=True, null=True)), + ('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/blog/migrations/__init__.py b/blog/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/blog/models.py b/blog/models.py new file mode 100644 index 0000000..88c2bb1 --- /dev/null +++ b/blog/models.py @@ -0,0 +1,16 @@ +from django.db import models +from django.utils import timezone + +class Post(models.Model): + author = models.ForeignKey('auth.User') + title = models.CharField(max_length=300) + text = models.TextField() + created_date = models.DateTimeField(default=timezone.now) + published_date = models.DateTimeField(blank=True, null=True) + + def publish(self): + self.published_date = timezone.now() + self.save() + + def __str__(self): + return self.title diff --git a/blog/tests.py b/blog/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/blog/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/blog/views.py b/blog/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/blog/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/mysite/django-girls.sublime-project b/mysite/django-girls.sublime-project index 24db303..6912d5a 100644 --- a/mysite/django-girls.sublime-project +++ b/mysite/django-girls.sublime-project @@ -3,6 +3,12 @@ [ { "path": "." + }, + { + "path": "/home/neil/Documents/programming/django-girls/blog" + }, + { + "path": "/home/neil/Documents/programming/django-girls" } ] } diff --git a/mysite/settings.py b/mysite/settings.py index fc1e965..ff02bb6 100644 --- a/mysite/settings.py +++ b/mysite/settings.py @@ -37,6 +37,7 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'blog' ] MIDDLEWARE = [ -- 2.34.1