Skip to content

Commit c8814a3

Browse files
committed
Add django-vue-graphql source code
1 parent 0f39387 commit c8814a3

33 files changed

+19290
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Python
2+
.python-version
3+
*.pyc
4+
5+
# SQLite
6+
db.sqlite3

django-vue-graphql/backend/backend/__init__.py

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import os
2+
3+
from django.core.asgi import get_asgi_application
4+
5+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backend.settings")
6+
7+
application = get_asgi_application()
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
from pathlib import Path
2+
3+
4+
BASE_DIR = Path(__file__).resolve().parent.parent
5+
6+
SECRET_KEY = "gmkd4-*ew4fv!w8p!9qm(o2-qpmc$&jng-2jm!4l3$x^pn#tmu"
7+
8+
DEBUG = True
9+
10+
ALLOWED_HOSTS = ["*"]
11+
12+
INSTALLED_APPS = [
13+
"django.contrib.admin",
14+
"django.contrib.auth",
15+
"django.contrib.contenttypes",
16+
"django.contrib.sessions",
17+
"django.contrib.messages",
18+
"django.contrib.staticfiles",
19+
"graphene_django",
20+
"corsheaders",
21+
"blog",
22+
]
23+
24+
MIDDLEWARE = [
25+
"django.middleware.security.SecurityMiddleware",
26+
"django.contrib.sessions.middleware.SessionMiddleware",
27+
"django.middleware.common.CommonMiddleware",
28+
"django.middleware.csrf.CsrfViewMiddleware",
29+
"django.contrib.auth.middleware.AuthenticationMiddleware",
30+
"django.contrib.messages.middleware.MessageMiddleware",
31+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
32+
"corsheaders.middleware.CorsMiddleware",
33+
]
34+
35+
ROOT_URLCONF = "backend.urls"
36+
37+
TEMPLATES = [
38+
{
39+
"BACKEND": "django.template.backends.django.DjangoTemplates",
40+
"DIRS": [],
41+
"APP_DIRS": True,
42+
"OPTIONS": {
43+
"context_processors": [
44+
"django.template.context_processors.debug",
45+
"django.template.context_processors.request",
46+
"django.contrib.auth.context_processors.auth",
47+
"django.contrib.messages.context_processors.messages",
48+
],
49+
},
50+
},
51+
]
52+
53+
WSGI_APPLICATION = "backend.wsgi.application"
54+
55+
DATABASES = {
56+
"default": {
57+
"ENGINE": "django.db.backends.sqlite3",
58+
"NAME": BASE_DIR / "db.sqlite3",
59+
}
60+
}
61+
62+
AUTH_PASSWORD_VALIDATORS = [
63+
{
64+
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
65+
},
66+
{
67+
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
68+
},
69+
{
70+
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
71+
},
72+
{
73+
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
74+
},
75+
]
76+
77+
LANGUAGE_CODE = "en-us"
78+
79+
TIME_ZONE = "UTC"
80+
81+
USE_I18N = True
82+
83+
USE_L10N = True
84+
85+
USE_TZ = True
86+
87+
STATIC_URL = "/static/"
88+
89+
GRAPHENE = {
90+
"SCHEMA": "blog.schema.schema",
91+
}
92+
93+
CORS_ORIGIN_ALLOW_ALL = False
94+
CORS_ORIGIN_WHITELIST = ("http://localhost:8080",)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from django.contrib import admin
2+
from django.urls import path
3+
from django.views.decorators.csrf import csrf_exempt
4+
from graphene_django.views import GraphQLView
5+
6+
7+
urlpatterns = [
8+
path("admin/", admin.site.urls),
9+
path("graphql", csrf_exempt(GraphQLView.as_view(graphiql=True))),
10+
]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import os
2+
3+
from django.core.wsgi import get_wsgi_application
4+
5+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backend.settings")
6+
7+
application = get_wsgi_application()

django-vue-graphql/backend/blog/__init__.py

Whitespace-only changes.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from django.contrib import admin
2+
3+
from blog.models import Profile, Post, Tag
4+
5+
6+
@admin.register(Profile)
7+
class ProfileAdmin(admin.ModelAdmin):
8+
model = Profile
9+
10+
11+
@admin.register(Tag)
12+
class TagAdmin(admin.ModelAdmin):
13+
model = Tag
14+
15+
16+
@admin.register(Post)
17+
class PostAdmin(admin.ModelAdmin):
18+
model = Post
19+
20+
list_display = (
21+
"id",
22+
"title",
23+
"subtitle",
24+
"slug",
25+
"publish_date",
26+
"published",
27+
)
28+
list_filter = (
29+
"published",
30+
"publish_date",
31+
)
32+
list_editable = (
33+
"title",
34+
"subtitle",
35+
"slug",
36+
"publish_date",
37+
"published",
38+
)
39+
search_fields = (
40+
"title",
41+
"subtitle",
42+
"slug",
43+
"body",
44+
)
45+
prepopulated_fields = {
46+
"slug": (
47+
"title",
48+
"subtitle",
49+
)
50+
}
51+
date_hierarchy = "publish_date"
52+
save_on_top = True
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.apps import AppConfig
2+
3+
4+
class BlogConfig(AppConfig):
5+
name = "blog"
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Generated by Django 3.1.4 on 2021-01-03 18:48
2+
3+
from django.conf import settings
4+
from django.db import migrations, models
5+
import django.db.models.deletion
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
initial = True
11+
12+
dependencies = [
13+
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
14+
]
15+
16+
operations = [
17+
migrations.CreateModel(
18+
name="Tag",
19+
fields=[
20+
(
21+
"id",
22+
models.AutoField(
23+
auto_created=True,
24+
primary_key=True,
25+
serialize=False,
26+
verbose_name="ID",
27+
),
28+
),
29+
("name", models.CharField(max_length=50, unique=True)),
30+
],
31+
),
32+
migrations.CreateModel(
33+
name="Profile",
34+
fields=[
35+
(
36+
"id",
37+
models.AutoField(
38+
auto_created=True,
39+
primary_key=True,
40+
serialize=False,
41+
verbose_name="ID",
42+
),
43+
),
44+
("website", models.URLField(blank=True, null=True)),
45+
("bio", models.CharField(blank=True, max_length=240, null=True)),
46+
(
47+
"user",
48+
models.OneToOneField(
49+
on_delete=django.db.models.deletion.PROTECT,
50+
to=settings.AUTH_USER_MODEL,
51+
),
52+
),
53+
],
54+
),
55+
migrations.CreateModel(
56+
name="Post",
57+
fields=[
58+
(
59+
"id",
60+
models.AutoField(
61+
auto_created=True,
62+
primary_key=True,
63+
serialize=False,
64+
verbose_name="ID",
65+
),
66+
),
67+
("title", models.CharField(max_length=255, unique=True)),
68+
("subtitle", models.CharField(blank=True, max_length=255, null=True)),
69+
("slug", models.SlugField(max_length=255, unique=True)),
70+
("body", models.TextField()),
71+
(
72+
"meta_description",
73+
models.CharField(blank=True, max_length=150, null=True),
74+
),
75+
("date_created", models.DateTimeField(auto_now_add=True)),
76+
("date_modified", models.DateTimeField(auto_now=True)),
77+
("publish_date", models.DateTimeField(blank=True, null=True)),
78+
("published", models.BooleanField(default=False)),
79+
(
80+
"author",
81+
models.ForeignKey(
82+
on_delete=django.db.models.deletion.PROTECT, to="blog.profile"
83+
),
84+
),
85+
("tags", models.ManyToManyField(blank=True, to="blog.Tag")),
86+
],
87+
options={
88+
"ordering": ["-publish_date"],
89+
},
90+
),
91+
]

0 commit comments

Comments
 (0)