-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Generated by Django 3.2.18 on 2023-08-22 09:14 | ||
|
||
import django.db.models.deletion | ||
import django.utils.timezone | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
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=200)), | ||
('text', models.TextField()), | ||
('created_date', models.DateTimeField(default=django.utils.timezone.now)), | ||
('published_date', models.DateTimeField(blank=True, null=True)), | ||
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,26 @@ | ||
"""Models for the blog app.""" | ||
|
||
from django.conf import settings | ||
from django.db import models | ||
from django.utils import timezone | ||
|
||
|
||
class Post(models.Model): | ||
"""A class to represent a post.""" | ||
|
||
author = models.ForeignKey( | ||
settings.AUTH_USER_MODEL, on_delete=models.CASCADE, | ||
) | ||
title = models.CharField(max_length=200) | ||
text = models.TextField() | ||
created_date = models.DateTimeField(default=timezone.now) | ||
published_date = models.DateTimeField(blank=True, null=True) | ||
|
||
def publish(self): | ||
"""Save the post entry.""" | ||
self.published_date = timezone.now | ||
self.save() | ||
|
||
def __str__(self): | ||
"""Return the post title.""" | ||
return str(self.title) |