Add dummy data
This commit is contained in:
@ -1,3 +1,11 @@
|
||||
from django.contrib import admin
|
||||
from .models import Post, Comment
|
||||
|
||||
@admin.register(Post)
|
||||
class PostAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
|
||||
@admin.register(Comment)
|
||||
class CommentAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
|
||||
# Register your models here.
|
||||
|
33
apps/back/migrations/0001_initial.py
Normal file
33
apps/back/migrations/0001_initial.py
Normal file
@ -0,0 +1,33 @@
|
||||
# Generated by Django 3.1.7 on 2021-03-09 20:10
|
||||
|
||||
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.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('title', models.CharField(max_length=200, unique=True)),
|
||||
('slug', models.SlugField(max_length=200, unique=True)),
|
||||
('updated_on', models.DateTimeField(auto_now=True)),
|
||||
('content', models.TextField()),
|
||||
('created_on', models.DateTimeField(auto_now_add=True)),
|
||||
('status', models.IntegerField(choices=[(0, 'Draft'), (1, 'Publish')], default=0)),
|
||||
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='blog_posts', to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
'ordering': ['-created_on'],
|
||||
},
|
||||
),
|
||||
]
|
31
apps/back/migrations/0002_auto_20210309_2020.py
Normal file
31
apps/back/migrations/0002_auto_20210309_2020.py
Normal file
@ -0,0 +1,31 @@
|
||||
# Generated by Django 3.1.7 on 2021-03-09 20:20
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('back', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='post',
|
||||
name='updated_on',
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Comment',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=20)),
|
||||
('body', models.CharField(max_length=128)),
|
||||
('created_on', models.DateTimeField(auto_now_add=True)),
|
||||
('post', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='back.post')),
|
||||
],
|
||||
options={
|
||||
'ordering': ['-created_on'],
|
||||
},
|
||||
),
|
||||
]
|
22
apps/back/migrations/0003_auto_20210309_2038.py
Normal file
22
apps/back/migrations/0003_auto_20210309_2038.py
Normal file
@ -0,0 +1,22 @@
|
||||
# Generated by Django 3.1.7 on 2021-03-09 20:38
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('back', '0002_auto_20210309_2020'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='post',
|
||||
name='slug',
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='post',
|
||||
name='author',
|
||||
field=models.CharField(max_length=20),
|
||||
),
|
||||
]
|
@ -1,3 +1,32 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
|
||||
STATUS = (
|
||||
(0,"Draft"),
|
||||
(1,"Publish")
|
||||
)
|
||||
|
||||
class Post(models.Model):
|
||||
title = models.CharField(max_length=200, unique=True)
|
||||
author = models.CharField(max_length=20)
|
||||
content = models.TextField()
|
||||
status = models.IntegerField(choices=STATUS, default=0)
|
||||
created_on = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ['-created_on']
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
class Comment(models.Model):
|
||||
name = models.CharField(max_length=20)
|
||||
body = models.CharField(max_length=128)
|
||||
post = models.ForeignKey(Post, on_delete= models.CASCADE)
|
||||
created_on = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ['-created_on']
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
Reference in New Issue
Block a user