Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Intro to Django

Fork this repo to use for your projects this week.
Fork this repo to use for your projects this week

## Reading

Expand Down
84 changes: 84 additions & 0 deletions djorg/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
"""
Django settings for djorg project.
Generated by 'django-admin startproject' using Django 2.1.4.
For more information on this file, see
https://docs.djangoproject.com/en/2.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/ref/settings/
"""
import os
from decouple import config
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


SECRET_KEY = config('SECRET_KEY')
DEBUG = config('DEBUG', cast=bool)
ALLOWED_HOSTS = []
INSTALLED_APPS = [
'notes.apps.NotesConfig',
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming this works, but I'm curious as to why you have this here instead of 'notes'.

'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'djorg.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'djorg.wsgi.application'

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]

LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True

STATIC_URL = '/static/'
20 changes: 20 additions & 0 deletions djorg/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""djorg URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path

urlpatterns = [
path('admin/', admin.site.urls),
]
15 changes: 15 additions & 0 deletions djorg/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

"""
WSGI config for djorg project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djorg.settings')

application = get_wsgi_application()
4 changes: 4 additions & 0 deletions notes/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from django.contrib import admin
from .models import Note, PersonalNote
admin.site.register(Note)
admin.site.register(PersonalNote)
26 changes: 26 additions & 0 deletions notes/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from rest_framework import serializers, viewsets
from .models import PersonalNote, Note

class PersonalNoteSerializer(serializers.HyperlinkedModelSerializer):

class Meta:
model = PersonalNote
fields = ('title', 'content')

def create(self, validated_data):
user = self.context['request'].user
note = PersonalNote.objects.create(user=user, **validated_data)
return note

class PersonalNoteViewSet(viewsets.ModelViewSet):
serializer_class = PersonalNoteSerializer
queryset = PersonalNote.objects.none()
def get_queryset(self):
user = self.request.user

if user.is_anonymous:
return PersonalNote.objects.none()
else:
return PersonalNote.objects.filter(user=user)


3 changes: 3 additions & 0 deletions notes/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.apps import AppConfig
class NotesConfig(AppConfig):
name = 'notes'
36 changes: 36 additions & 0 deletions notes/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Generated by Django 2.1.4 on 2018-12-04 04:32

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import uuid


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='Note',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('title', models.CharField(max_length=200)),
('content', models.TextField(blank=True)),
('created_at', models.DateTimeField(auto_now_add=True)),
('last_modified', models.DateTimeField(auto_now=True)),
],
),
migrations.CreateModel(
name='PersonalNote',
fields=[
('note_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='notes.Note')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
bases=('notes.note',),
),
]
25 changes: 25 additions & 0 deletions notes/migrations/0002_auto_20181203_1835.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 2.1.4 on 2018-12-04 03:53

from django.db import migrations, models
import django.utils.timezone


class Migration(migrations.Migration):

dependencies = [
('notes', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='note',
name='created_at',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
preserve_default=False,
),
migrations.AddField(
model_name='note',
name='last_modified',
field=models.DateTimeField(auto_now=True),
),
]
24 changes: 24 additions & 0 deletions notes/migrations/0003_personalnote.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 2.1.4 on 2018-12-04 04:14

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('notes', '0002_auto_20181203_1835'),
]

operations = [
migrations.CreateModel(
name='PersonalNote',
fields=[
('note_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='notes.Note')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
bases=('notes.note',),
),
]
24 changes: 24 additions & 0 deletions notes/migrations/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 2.1.4 on 2018-12-04 01:32

from django.db import migrations, models
import uuid


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Note',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('title', models.CharField(max_length=200)),
('content', models.TextField(blank=True)),
('pub_date', models.DateTimeField(verbose_name='date_published')),
],
),
]
17 changes: 17 additions & 0 deletions notes/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from django.db import models
from uuid import uuid4
from django.contrib.auth.models import User


class Note(models.Model):
id = models.UUIDField(primary_key=True, default=uuid4, editable=False)
title = models.CharField(max_length=200)
content = models.TextField(blank=True)
created_at = models.DateTimeField(auto_now_add=True)
last_modified = models.DateTimeField(auto_now=True)

def __str__(self):
return F"Title: {self.title}, Content: {self.content}"

class PersonalNote(Note):
user = models.ForeignKey(User, on_delete=models.CASCADE)
3 changes: 3 additions & 0 deletions notes/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
3 changes: 3 additions & 0 deletions notes/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.
Loading