Skip to content

Commit a7791e2

Browse files
committed
Add blog example app to durable objects template
1 parent cb25dfa commit a7791e2

File tree

18 files changed

+687
-4
lines changed

18 files changed

+687
-4
lines changed

templates/d1/src/app/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
'django.contrib.messages',
3939
'django.contrib.staticfiles',
4040

41-
'blog'
41+
'blog',
4242
]
4343

4444
MIDDLEWARE = [

templates/d1/src/app/urls.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def run_migrations_view(request):
4444
call_command("migrate")
4545
return JsonResponse({"status": "success", "message": "Migrations applied."})
4646
except Exception as e:
47-
raise e
4847
return JsonResponse({"status": "error", "message": str(e)}, status=500)
4948

5049

templates/durable-objects/src/app/settings.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
'django.contrib.sessions',
3838
'django.contrib.messages',
3939
'django.contrib.staticfiles',
40+
41+
'blog',
4042
]
4143

4244
MIDDLEWARE = [
@@ -54,7 +56,9 @@
5456
TEMPLATES = [
5557
{
5658
'BACKEND': 'django.template.backends.django.DjangoTemplates',
57-
'DIRS': [],
59+
'DIRS': [
60+
BASE_DIR.joinpath('templates')
61+
],
5862
'APP_DIRS': True,
5963
'OPTIONS': {
6064
'context_processors': [

templates/durable-objects/src/app/urls.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from django.contrib.auth import get_user_model
1919
from django.core.management import call_command
2020
from django.http import JsonResponse
21-
from django.urls import path
21+
from django.urls import path, include
2222
from django.contrib.auth.decorators import user_passes_test
2323

2424
def is_superuser(user):
@@ -48,6 +48,8 @@ def run_migrations_view(request):
4848

4949

5050
urlpatterns = [
51+
path('', include('blog.urls')),
52+
5153
path('admin/', admin.site.urls),
5254
# Management endpoints - secure these appropriately for your application
5355
path('__create_admin__/', create_admin_view, name='create_admin'),

templates/durable-objects/src/blog/__init__.py

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
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)
Lines changed: 6 additions & 0 deletions
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'
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Generated by Django 5.1.2 on 2025-07-06 13:30
2+
3+
import django.utils.timezone
4+
from django.db import migrations, models
5+
6+
7+
def insert_dummy_blog_post(apps, schema_editor):
8+
Post = apps.get_model('blog', 'Post')
9+
10+
# Insert the record
11+
Post.objects.create(
12+
title='Example Post',
13+
content="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
14+
)
15+
16+
17+
class Migration(migrations.Migration):
18+
19+
initial = True
20+
21+
dependencies = [
22+
]
23+
24+
operations = [
25+
migrations.CreateModel(
26+
name='Post',
27+
fields=[
28+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
29+
('title', models.CharField(max_length=200)),
30+
('content', models.TextField()),
31+
('pub_date', models.DateTimeField(default=django.utils.timezone.now)),
32+
],
33+
),
34+
migrations.RunPython(
35+
code=insert_dummy_blog_post,
36+
),
37+
]

templates/durable-objects/src/blog/migrations/__init__.py

Whitespace-only changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from django.db import models
2+
from django.utils import timezone
3+
4+
class Post(models.Model):
5+
title = models.CharField(max_length=200)
6+
content = models.TextField()
7+
pub_date = models.DateTimeField(default=timezone.now)
8+
9+
def __str__(self):
10+
return self.title

0 commit comments

Comments
 (0)