From 47bbec8dfe9d5a2edf39ef916a5bc281718dd77f Mon Sep 17 00:00:00 2001 From: Pratyush Desai Date: Sat, 8 Jan 2022 12:21:22 +0530 Subject: [PATCH] blog post init --- website/blog/admin.py | 4 +++- website/blog/migrations/0001_initial.py | 15 ++++++++++----- website/blog/models.py | 14 +++++++------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/website/blog/admin.py b/website/blog/admin.py index 8c38f3f..6bd12cc 100644 --- a/website/blog/admin.py +++ b/website/blog/admin.py @@ -1,3 +1,5 @@ from django.contrib import admin -# Register your models here. +from blog.models import * + +admin.site.register(Post) \ No newline at end of file diff --git a/website/blog/migrations/0001_initial.py b/website/blog/migrations/0001_initial.py index 7acd9e8..3864afe 100644 --- a/website/blog/migrations/0001_initial.py +++ b/website/blog/migrations/0001_initial.py @@ -1,6 +1,7 @@ -# Generated by Django 4.0 on 2022-01-07 23:05 +# Generated by Django 4.0 on 2022-01-08 06:45 from django.db import migrations, models +import django.db.models.deletion class Migration(migrations.Migration): @@ -8,6 +9,7 @@ class Migration(migrations.Migration): initial = True dependencies = [ + ('auth', '0012_alter_user_first_name_max_length'), ] operations = [ @@ -15,10 +17,13 @@ class Migration(migrations.Migration): name='Post', fields=[ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('title', models.CharField(max_length=200, unique=True)), - ('updated_on', models.DateTimeField(auto_now=True)), - ('created_on', models.DateTimeField(auto_now_add=True)), - ('content', models.TextField()), + ('created', models.DateTimeField(auto_now_add=True)), + ('title', models.CharField(blank=True, default='', max_length=100)), + ('body', models.TextField(blank=True, default='')), + ('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='posts', to='auth.user')), ], + options={ + 'ordering': ['created'], + }, ), ] diff --git a/website/blog/models.py b/website/blog/models.py index 78c675e..63cbb9b 100644 --- a/website/blog/models.py +++ b/website/blog/models.py @@ -8,11 +8,11 @@ STATUS = ( (1,"Publish") ) # Create your models here. - class Post(models.Model): - title = models.CharField(max_length=200, unique=True) - # author = models.ForeignKey('user.auth',on_delete=models.CASCADE) - updated_on =models.DateTimeField(auto_now= True) - created_on = models.DateTimeField(auto_now_add=True) - content = models.TextField() - # status = models.IntegerChoices() \ No newline at end of file + created = models.DateTimeField(auto_now_add=True) + title = models.CharField(max_length=100, blank=True, default='') + body = models.TextField(blank=True, default='') + owner = models.ForeignKey('auth.User', related_name='posts', on_delete=models.CASCADE) + + class Meta: + ordering = ['created'] \ No newline at end of file