Skip to content

Commit 8064cba

Browse files
committed
My Django Girls app, first commit
0 parents  commit 8064cba

File tree

4,809 files changed

+707039
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

4,809 files changed

+707039
-0
lines changed

blog/__init__.py

Whitespace-only changes.

blog/admin.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from django.contrib import admin
2+
from .models import Post
3+
4+
admin.site.register(Post)

blog/apps.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class BlogConfig(AppConfig):
5+
default_auto_field = 'django.db.models.BigAutoField'
6+
name = 'blog'

blog/forms.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from django import forms
2+
3+
from .models import Post
4+
5+
class PostForm(forms.ModelForm):
6+
7+
class Meta:
8+
model = Post
9+
fields = ('title', 'text',)

blog/migrations/0001_initial.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Generated by Django 3.2.6 on 2021-08-08 17:41
2+
3+
from django.conf import settings
4+
from django.db import migrations, models
5+
import django.db.models.deletion
6+
import django.utils.timezone
7+
8+
9+
class Migration(migrations.Migration):
10+
11+
initial = True
12+
13+
dependencies = [
14+
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
15+
]
16+
17+
operations = [
18+
migrations.CreateModel(
19+
name='Post',
20+
fields=[
21+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
22+
('title', models.CharField(max_length=200)),
23+
('text', models.TextField()),
24+
('created_date', models.DateTimeField(default=django.utils.timezone.now)),
25+
('published_date', models.DateTimeField(blank=True, null=True)),
26+
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
27+
],
28+
),
29+
]

blog/migrations/__init__.py

Whitespace-only changes.

blog/models.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from django.conf import settings
2+
from django.db import models
3+
from django.utils import timezone
4+
5+
6+
class Post(models.Model):
7+
author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
8+
title = models.CharField(max_length=200)
9+
text = models.TextField()
10+
created_date = models.DateTimeField(default=timezone.now)
11+
published_date = models.DateTimeField(blank=True, null=True)
12+
13+
def publish(self):
14+
self.published_date = timezone.now()
15+
self.save()
16+
17+
def __str__(self):
18+
return self.title

blog/static/css/blog.css

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
h1 a {
2+
color: #FCA205;
3+
font-family: 'Lobster';
4+
}
5+
6+
.page-header {
7+
background-color: #ff9400;
8+
margin-top: 0;
9+
padding: 20px 20px 20px 40px;
10+
}
11+
12+
.page-header h1, .page-header h1 a, .page-header h1 a:visited, .page-header h1 a:active {
13+
color: #ffffff;
14+
font-size: 36pt;
15+
text-decoration: none;
16+
}
17+
18+
.content {
19+
margin-left: 40px;
20+
}
21+
22+
h1, h2, h3, h4 {
23+
font-family: 'Lobster', cursive;
24+
}
25+
26+
.date {
27+
color: #828282;
28+
}
29+
30+
.save {
31+
float: right;
32+
}
33+
34+
.post-form textarea, .post-form input {
35+
width: 100%;
36+
}
37+
38+
.top-menu, .top-menu:hover, .top-menu:visited {
39+
color: #ffffff;
40+
float: right;
41+
font-size: 26pt;
42+
margin-right: 20px;
43+
}
44+
45+
.post {
46+
margin-bottom: 70px;
47+
}
48+
49+
.post h1 a, .post h1 a:visited {
50+
color: #000000;
51+
}

blog/templates/blog/base.html

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{% load static %}
2+
<html>
3+
<head>
4+
<title>Django Girls blog</title>
5+
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
6+
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
7+
<link href='//fonts.googleapis.com/css?family=Lobster&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
8+
<link rel="stylesheet" href="{% static 'css/blog.css' %}">
9+
</head>
10+
<div class="page-header">
11+
{% if user.is_authenticated %}
12+
<a href="{% url 'post_new' %}" class="top-menu"><span class="glyphicon glyphicon-plus"></span></a>
13+
{% endif %}
14+
<h1><a href="/">Django Girls Blog</a></h1>
15+
</div>
16+
<div class="content container">
17+
<div class="row">
18+
<div class="col-md-8">
19+
{% block content %}
20+
{% endblock %}
21+
</div>
22+
</div>
23+
</div>
24+
</html>

blog/templates/blog/post_detail.html

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{% extends 'blog/base.html' %}
2+
3+
{% block content %}
4+
<div class="post">
5+
{% if post.published_date %}
6+
<div class="date">
7+
{{ post.published_date }}
8+
</div>
9+
{% endif %}
10+
{% if user.is_authenticated %}
11+
<a class="btn btn-default" href="{% url 'post_edit' pk=post.pk %}"><span class="glyphicon glyphicon-pencil"></span></a>
12+
{% endif %}
13+
<h1>{{ post.title }}</h1>
14+
<p>{{ post.text|linebreaksbr }}</p>
15+
</div>
16+
{% endblock %}

blog/templates/blog/post_edit.html

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{% extends 'blog/base.html' %}
2+
3+
{% block content %}
4+
<h1>New post</h1>
5+
<form method="POST" class="post-form">{% csrf_token %}
6+
{{ form.as_p }}
7+
<button type="submit" class="save btn btn-default">Save</button>
8+
</form>
9+
{% endblock %}

blog/templates/blog/post_list.html

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{% extends 'blog/base.html' %}
2+
3+
{% block content %}
4+
{% for post in posts %}
5+
<div class="post">
6+
<div class="date">
7+
{{ post.published_date }}
8+
</div>
9+
<h1><a href="{% url 'post_detail' pk=post.pk %}">{{ post.title }}</a></h1>
10+
<p>{{ post.text|linebreaksbr }}</p>
11+
</div>
12+
{% endfor %}
13+
{% endblock %}

blog/tests.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

blog/urls.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from django.urls import path
2+
from . import views
3+
4+
urlpatterns = [
5+
path('', views.post_list, name='post_list'),
6+
path('post/<int:pk>/', views.post_detail, name = 'post_detail'),
7+
path('post/new', views.post_new, name='post_new'),
8+
path('post/<int:pk>/edit/', views.post_edit, name='post_edit'),
9+
10+
]

blog/views.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from django.shortcuts import render, get_object_or_404, redirect
2+
from django.utils import timezone
3+
from .models import Post
4+
from .forms import PostForm
5+
6+
# Create your views here.
7+
8+
def post_list(request):
9+
posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('published_date')
10+
return render(request, 'blog/post_list.html', {'posts':posts})
11+
12+
def post_detail(request, pk):
13+
post = get_object_or_404(Post, pk=pk)
14+
return render(request, 'blog/post_detail.html', {'post': post})
15+
16+
def post_new(request):
17+
if request.method == "POST":
18+
form = PostForm(request.POST)
19+
if form.is_valid():
20+
post = form.save(commit=False)
21+
post.author = request.user
22+
post.published_date = timezone.now()
23+
post.save()
24+
return redirect('post_detail', pk=post.pk)
25+
else:
26+
form = PostForm()
27+
return render(request, 'blog/post_edit.html', {'form': form})
28+
29+
def post_edit(request, pk):
30+
post = get_object_or_404(Post, pk=pk)
31+
if request.method == "POST":
32+
form = PostForm(request.POST, instance=post)
33+
if form.is_valid():
34+
post = form.save(commit=False)
35+
post.author = request.user
36+
post.published_date = timezone.now()
37+
post.save()
38+
return redirect('post_detail', pk=post.pk)
39+
else:
40+
form = PostForm(instance=post)
41+
return render(request, 'blog/post_edit.html', {'form': form})

db.sqlite3

140 KB
Binary file not shown.

diary/__init__.py

Whitespace-only changes.

diary/admin.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.contrib import admin
2+
from .models import Post
3+
4+
admin.site.register(Post)
5+
6+
# Register your models here.

diary/apps.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class DiaryConfig(AppConfig):
5+
default_auto_field = 'django.db.models.BigAutoField'
6+
name = 'diary'

diary/migrations/0001_initial.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Generated by Django 3.2.6 on 2021-08-06 09:35
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
initial = True
9+
10+
dependencies = [
11+
]
12+
13+
operations = [
14+
migrations.CreateModel(
15+
name='Post',
16+
fields=[
17+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18+
('title', models.CharField(max_length=20)),
19+
('subtitle', models.CharField(max_length=30)),
20+
('published_date', models.DateTimeField(auto_now_add=True)),
21+
('content', models.TextField()),
22+
],
23+
),
24+
]

diary/migrations/__init__.py

Whitespace-only changes.

diary/models.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from django.db import models
2+
3+
# Create your models here.
4+
class Post(models.Model):
5+
title = models.CharField(max_length=20)
6+
subtitle = models.CharField(max_length=30)
7+
published_date = models.DateTimeField(auto_now_add=True)
8+
content = models.TextField()
9+

diary/tests.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

diary/views.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.shortcuts import render
2+
3+
# Create your views here.

manage.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
"""Django's command-line utility for administrative tasks."""
3+
import os
4+
import sys
5+
6+
7+
def main():
8+
"""Run administrative tasks."""
9+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'post.settings')
10+
try:
11+
from django.core.management import execute_from_command_line
12+
except ImportError as exc:
13+
raise ImportError(
14+
"Couldn't import Django. Are you sure it's installed and "
15+
"available on your PYTHONPATH environment variable? Did you "
16+
"forget to activate a virtual environment?"
17+
) from exc
18+
execute_from_command_line(sys.argv)
19+
20+
21+
if __name__ == '__main__':
22+
main()

post/__init__.py

Whitespace-only changes.

post/asgi.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
ASGI config for post project.
3+
4+
It exposes the ASGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.asgi import get_asgi_application
13+
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'post.settings')
15+
16+
application = get_asgi_application()

0 commit comments

Comments
 (0)