Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finish Introduction and Django Admin #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Binary file added blango/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file added blango/__pycache__/settings.cpython-36.pyc
Binary file not shown.
Binary file added blango/__pycache__/urls.cpython-36.pyc
Binary file not shown.
Binary file added blango/__pycache__/wsgi.cpython-36.pyc
Binary file not shown.
17 changes: 13 additions & 4 deletions blango/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""

from pathlib import Path
import os

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
Expand All @@ -25,7 +26,14 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []
ALLOWED_HOSTS = ['*']
X_FRAME_OPTIONS = 'ALLOW-FROM ' + os.environ.get('CODIO_HOSTNAME') + '-8000.codio.io'
CSRF_COOKIE_SAMESITE = None
CSRF_TRUSTED_ORIGINS = ['https://' + os.environ.get('CODIO_HOSTNAME') + '-8000.codio.io']
CSRF_COOKIE_SECURE = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SAMESITE = 'None'
SESSION_COOKIE_SAMESITE = 'None'


# Application definition
Expand All @@ -37,24 +45,25 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog',
]

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

ROOT_URLCONF = 'blango.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [BASE_DIR / 'templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
Expand Down
4 changes: 3 additions & 1 deletion blango/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import path, include
import blog.views

urlpatterns = [
path('admin/', admin.site.urls),
path("", blog.views.index)
]
Empty file added blog/__init__.py
Empty file.
Binary file added blog/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file added blog/__pycache__/admin.cpython-36.pyc
Binary file not shown.
Binary file added blog/__pycache__/apps.cpython-36.pyc
Binary file not shown.
Binary file added blog/__pycache__/models.cpython-36.pyc
Binary file not shown.
Binary file added blog/__pycache__/views.cpython-36.pyc
Binary file not shown.
10 changes: 10 additions & 0 deletions blog/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.contrib import admin
from blog.models import Tag, Post

class PostAdmin(admin.ModelAdmin):
prepopulated_fields = {"slug": ("title",)}

admin.site.register(Tag)
admin.site.register(Post)

# Register your models here.
6 changes: 6 additions & 0 deletions blog/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class BlogConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'blog'
39 changes: 39 additions & 0 deletions blog/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Generated by Django 3.2.5 on 2023-11-22 11:39

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='Tag',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('value', models.TextField(max_length=100)),
],
),
migrations.CreateModel(
name='Post',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('modified_at', models.DateTimeField(auto_now=True)),
('published_at', models.DateTimeField(blank=True, null=True)),
('title', models.TextField(max_length=100)),
('slug', models.SlugField()),
('summary', models.TextField(max_length=500)),
('content', models.TextField()),
('author', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
('tags', models.ManyToManyField(related_name='posts', to='blog.Tag')),
],
),
]
Empty file added blog/migrations/__init__.py
Empty file.
Binary file not shown.
Binary file added blog/migrations/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
26 changes: 26 additions & 0 deletions blog/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from django.db import models
from django.conf import settings

class Tag(models.Model):
value = models.TextField(max_length=100)

def __str__(self):
return self.value

class Post(models.Model):
author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.PROTECT)
created_at = models.DateTimeField(auto_now_add=True)
modified_at = models.DateTimeField(auto_now=True)
published_at = models.DateTimeField(blank=True, null=True)
title = models.TextField(max_length=100)
slug = models.SlugField()
summary = models.TextField(max_length=500)
content = models.TextField()
tags = models.ManyToManyField(Tag, related_name="posts")

def __str__(self):
return self.title



# Create your models here.
3 changes: 3 additions & 0 deletions blog/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.
6 changes: 6 additions & 0 deletions blog/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.shortcuts import render

def index(request):
return render(request, "blog/index.html")

# Create your views here.
Binary file added db.sqlite3
Binary file not shown.
17 changes: 17 additions & 0 deletions templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<title>Hello, world!</title>
</head>
<body>
<div class="container bg-dark text-light">
{% block content %}

{% endblock %}
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
</body>
</html>
4 changes: 4 additions & 0 deletions templates/blog/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% extends "base.html" %}
{% block content %}
<h2>Hello in a Container</h2>
{% endblock %}