It's mainly a very simple blog without comments and other stuff.
Main purpose is to post short articles, called "notes".
It's loosely based on some Django tutorials.
This is the very first commit. The application is able to list the
notes and to display a single note.
--- /dev/null
+__pycache__
+db.sqlite3
--- /dev/null
+#!/usr/bin/env python
+"""Django's command-line utility for administrative tasks."""
+import os
+import sys
+
+
+def main():
+ """Run administrative tasks."""
+ os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pcdenotes.settings')
+ try:
+ from django.core.management import execute_from_command_line
+ except ImportError as exc:
+ raise ImportError(
+ "Couldn't import Django. Are you sure it's installed and "
+ "available on your PYTHONPATH environment variable? Did you "
+ "forget to activate a virtual environment?"
+ ) from exc
+ execute_from_command_line(sys.argv)
+
+
+if __name__ == '__main__':
+ main()
--- /dev/null
+from django.contrib import admin
+from .models import Note
+
+# Register your models here.
+
+class NoteAdmin(admin.ModelAdmin):
+ list_display = ('title', 'status',)
+ list_filter = ('status',)
+ search_fields = ('title', 'content',)
+
+
+admin.site.register(Note, NoteAdmin)
\ No newline at end of file
--- /dev/null
+from django.apps import AppConfig
+
+
+class NotesConfig(AppConfig):
+ default_auto_field = 'django.db.models.BigAutoField'
+ name = 'notes'
--- /dev/null
+# Generated by Django 3.2.11 on 2022-01-19 20:18
+
+from django.conf import settings
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ initial = True
+
+ dependencies = [
+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='Note',
+ fields=[
+ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('title', models.CharField(max_length=250, unique=True)),
+ ('slug', models.SlugField(max_length=250, unique=True)),
+ ('content', models.TextField()),
+ ('status', models.IntegerField(choices=[(0, 'Draft'), (1, 'Published')], default=0)),
+ ('created_at', models.DateTimeField(auto_now_add=True)),
+ ('updated_at', models.DateTimeField(auto_now=True)),
+ ('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='notes_posted', to=settings.AUTH_USER_MODEL)),
+ ],
+ options={
+ 'ordering': ['-created_at'],
+ },
+ ),
+ ]
--- /dev/null
+from django.db import models
+from django.contrib.auth.models import User
+from django.urls import reverse
+
+# Create your models here.
+
+NOTE_STATUS = ((0, "Draft"),
+ (1, "Published"))
+
+class Note(models.Model):
+ title = models.CharField(max_length=250, unique=True)
+ slug = models.SlugField(max_length=250, unique=True)
+ author = models.ForeignKey(User, on_delete=models.CASCADE, related_name='notes_posted')
+ content = models.TextField()
+ status = models.IntegerField(choices=NOTE_STATUS, default=0)
+
+ created_at = models.DateTimeField(auto_now_add=True)
+ updated_at = models.DateTimeField(auto_now=True)
+
+ class Meta:
+ ordering = ['-created_at']
+
+ def __str__(self):
+ return self.title
+
+ def get_absolute_url(self):
+ return reverse("notes:note_detail", kwargs={"note_slug": self.slug})
+ #return "/notes/%s" % (self.slug)
+
--- /dev/null
+{% load markdownify %}
+<!DOCTYPE html>
+
+<html lang="de">
+<head>
+ <title>{{ note.title }}</title>
+ <meta charset="UTF-8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+</head>
+<body>
+
+ <h1>{{ note.title }}</h1>
+
+ <div>{{ note.content|linebreaksbr|markdownify }}</div>
+
+ <p>Date: {{ note.created_at|date:"Y-m-d H:i" }}</p>
+
+</body>
+</html>
--- /dev/null
+{% load markdownify %}
+<!DOCTYPE html>
+
+<html lang="de">
+<head>
+ <title>Notes</title>
+ <meta charset="UTF-8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+</head>
+<body>
+
+ <h1>Notes</h1>
+ {% for note in notes %}
+ <h2>{{ note.title }}</h2>
+ <p>ID: {{ note.id }}</p>
+ <div>{{ note.content|linebreaksbr|markdownify }}</div>
+ <p>Link: <a href="{{ note.get_absolute_url }}">View</a></p>
+ <p>Date: {{ note.created_at|date:"Y-m-d H:i" }}</p>
+ {% empty %}
+ <p>No notes</p>
+ {% endfor %}
+
+ <p>Number of notes: {{ notes_count }}</p>
+
+</body>
+</html>
--- /dev/null
+from django.test import TestCase
+
+# Create your tests here.
--- /dev/null
+from django.urls import path
+from . import views
+
+app_name = 'notes'
+
+urlpatterns=[
+ path('', views.note_list, name="note_list"),
+ path('notes/<slug:note_slug>', views.note_detail, name="note_detail"),
+]
\ No newline at end of file
--- /dev/null
+from django.shortcuts import render, get_object_or_404
+from .models import Note
+
+# Create your views here.
+
+def note_list(request):
+ notes = Note.objects.filter(status=1)
+ notes_count = Note.objects.filter(status=1).count()
+ return render(request, 'note_list.html', {'notes': notes, 'notes_count': notes_count})
+
+def note_detail(request, note_slug):
+ note = get_object_or_404(Note, slug=note_slug, status=1)
+ return render(request, 'note_detail.html', {'note': note})
\ No newline at end of file
--- /dev/null
+"""
+ASGI config for pcdenotes project.
+
+It exposes the ASGI callable as a module-level variable named ``application``.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
+"""
+
+import os
+
+from django.core.asgi import get_asgi_application
+
+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pcdenotes.settings')
+
+application = get_asgi_application()
--- /dev/null
+"""
+Django settings for pcdenotes project.
+
+Generated by 'django-admin startproject' using Django 3.2.11.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/3.2/topics/settings/
+
+For the full list of settings and their values, see
+https://docs.djangoproject.com/en/3.2/ref/settings/
+"""
+
+from pathlib import Path
+
+# Build paths inside the project like this: BASE_DIR / 'subdir'.
+BASE_DIR = Path(__file__).resolve().parent.parent
+
+
+# Quick-start development settings - unsuitable for production
+# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
+
+# SECURITY WARNING: keep the secret key used in production secret!
+SECRET_KEY = 'django-insecure-(bf$#80p=*wkj(yh$)3oec0nn#46k$8(m#hx4yx8d02kcog3$q'
+
+# SECURITY WARNING: don't run with debug turned on in production!
+DEBUG = True
+
+ALLOWED_HOSTS = []
+
+
+# Application definition
+
+INSTALLED_APPS = [
+ 'django.contrib.admin',
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sessions',
+ 'django.contrib.messages',
+ 'django.contrib.staticfiles',
+ 'markdownify.apps.MarkdownifyConfig',
+ 'notes',
+]
+
+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 = 'pcdenotes.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 = 'pcdenotes.wsgi.application'
+
+
+# Database
+# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
+
+DATABASES = {
+ 'default': {
+ 'ENGINE': 'django.db.backends.sqlite3',
+ 'NAME': BASE_DIR / 'db.sqlite3',
+ }
+}
+
+
+# Password validation
+# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
+
+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',
+ },
+]
+
+
+# Internationalization
+# https://docs.djangoproject.com/en/3.2/topics/i18n/
+
+LANGUAGE_CODE = 'en-us'
+
+TIME_ZONE = 'UTC'
+
+USE_I18N = True
+
+USE_L10N = True
+
+USE_TZ = True
+
+
+# Static files (CSS, JavaScript, Images)
+# https://docs.djangoproject.com/en/3.2/howto/static-files/
+
+STATIC_URL = '/static/'
+
+# Default primary key field type
+# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
+
+DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
+
+MARKDOWNIFY = {
+ "default": {
+ #"STRIP": False,
+ "BLEACH": False
+ }
+}
\ No newline at end of file
--- /dev/null
+"""pcdenotes URL Configuration
+
+The `urlpatterns` list routes URLs to views. For more information please see:
+ https://docs.djangoproject.com/en/3.2/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, include
+
+urlpatterns = [
+ path('admin/', admin.site.urls),
+ path('', include('notes.urls')),
+]
--- /dev/null
+"""
+WSGI config for pcdenotes 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/3.2/howto/deployment/wsgi/
+"""
+
+import os
+
+from django.core.wsgi import get_wsgi_application
+
+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pcdenotes.settings')
+
+application = get_wsgi_application()
--- /dev/null
+asgiref==3.4.1
+bleach==4.1.0
+Django==3.2.11
+django-markdownify==0.9.0
+importlib-metadata==4.8.3
+Markdown==3.3.6
+packaging==21.3
+pkg-resources==0.0.0
+pyparsing==3.0.6
+pytz==2021.3
+six==1.16.0
+sqlparse==0.4.2
+typing-extensions==4.0.1
+webencodings==0.5.1
+zipp==3.6.0