-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create a blog Django app #20
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# VS Code | ||
.vscode | ||
|
||
### Django ### | ||
*.log | ||
*.pot | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
exclude: '^blog/migrations/' | ||
repos: | ||
- repo: https://github.com/asottile/add-trailing-comma | ||
rev: v2.4.0 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""A Django app for blog.""" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Django admin panel for the blog app.""" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
"""Configuration file of the blog app.""" | ||
|
||
from django.apps import AppConfig | ||
|
||
|
||
class BlogConfig(AppConfig): | ||
"""A class for the blog app configuration.""" | ||
|
||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'blog' |
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)), | ||
], | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Martolivna I want you to write tests for this model. Create a Make sure to call every method you declared in this class. Bonus: you can also integrate coverage reporting like so https://adamj.eu/tech/2019/04/30/getting-a-django-application-to-100-percent-coverage/. |
||
"""A class to represent a post.""" | ||
webknjaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
author = models.ForeignKey( | ||
settings.AUTH_USER_MODEL, on_delete=models.CASCADE, | ||
Martolivna marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
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.""" | ||
webknjaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.published_date = timezone.now | ||
self.save() | ||
|
||
def __str__(self): | ||
"""Return the post title.""" | ||
webknjaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return str(self.title) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Tests for the blog app.""" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Views of the blog app.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few problems here: