diff --git a/.gitignore b/.gitignore index 4162e6f..1e555de 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# VS Code +.vscode + ### Django ### *.log *.pot diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 115a287..e350327 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,3 +1,4 @@ +exclude: '^blog/migrations/' repos: - repo: https://github.com/asottile/add-trailing-comma rev: v2.4.0 diff --git a/blog/__init__.py b/blog/__init__.py new file mode 100644 index 0000000..3b88414 --- /dev/null +++ b/blog/__init__.py @@ -0,0 +1 @@ +"""A Django app for blog.""" diff --git a/blog/admin.py b/blog/admin.py new file mode 100644 index 0000000..2c26065 --- /dev/null +++ b/blog/admin.py @@ -0,0 +1 @@ +"""Django admin panel for the blog app.""" diff --git a/blog/apps.py b/blog/apps.py new file mode 100644 index 0000000..af82708 --- /dev/null +++ b/blog/apps.py @@ -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' diff --git a/blog/migrations/0001_initial.py b/blog/migrations/0001_initial.py new file mode 100644 index 0000000..dc70f16 --- /dev/null +++ b/blog/migrations/0001_initial.py @@ -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)), + ], + ), + ] diff --git a/blog/migrations/__init__.py b/blog/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/blog/models.py b/blog/models.py new file mode 100644 index 0000000..1010da7 --- /dev/null +++ b/blog/models.py @@ -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): + """A blog post model.""" + + 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): + """Mark the post published.""" + self.published_date = timezone.now + self.save() + + def __str__(self): + """Render a Post representation as a string.""" + return str(self.title) diff --git a/blog/tests.py b/blog/tests.py new file mode 100644 index 0000000..f4694fe --- /dev/null +++ b/blog/tests.py @@ -0,0 +1 @@ +"""Tests for the blog app.""" diff --git a/blog/views.py b/blog/views.py new file mode 100644 index 0000000..cb4c6a0 --- /dev/null +++ b/blog/views.py @@ -0,0 +1 @@ +"""Views of the blog app.""" diff --git a/mysite/settings.py b/mysite/settings.py index 3e04f11..2bdcdde 100644 --- a/mysite/settings.py +++ b/mysite/settings.py @@ -20,7 +20,7 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = ['127.0.0.1'] +ALLOWED_HOSTS = ['127.0.0.1', 'localhost'] # Application definition @@ -32,6 +32,7 @@ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'blog', ] MIDDLEWARE = [