Add POST model

master
Patrick 2 years ago
parent 35f84d18ba
commit 7fb9481dbf

@ -37,6 +37,7 @@ INSTALLED_APPS = [
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'theblog'
] ]
MIDDLEWARE = [ MIDDLEWARE = [

@ -15,8 +15,9 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
""" """
from django.contrib import admin from django.contrib import admin
from django.urls import path from django.urls import path, include
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('', include('theblog.urls')),
] ]

@ -0,0 +1,5 @@
from django.contrib import admin
from .models import Post
admin.site.register(Post)

@ -0,0 +1,6 @@
from django.apps import AppConfig
class TheblogConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'theblog'

@ -0,0 +1,26 @@
# Generated by Django 4.2.6 on 2023-10-23 18:45
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='Post',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=255)),
('body', models.TextField()),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]

@ -0,0 +1,11 @@
from django.db import models
from django.contrib.auth.models import User
class Post(models.Model):
title = models.CharField(max_length=255)
author = models.ForeignKey(User, on_delete=models.CASCADE)
body = models.TextField()
def __str__(self):
return self.title + ' | ' + str(self.author)

@ -0,0 +1 @@
<h1>Hello World!</h1>

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

@ -0,0 +1,7 @@
from django.urls import path
from . import views
urlpatterns = [
path('', views.home, name='home')
]

@ -0,0 +1,5 @@
from django.shortcuts import render
def home(request):
return render(request, 'home.html', {})
Loading…
Cancel
Save