Compare commits
3 commits
3eae827ed5
...
da7075a904
| Author | SHA1 | Date | |
|---|---|---|---|
| da7075a904 | |||
| 0945dc5b6b | |||
| a983121a55 |
12 changed files with 92 additions and 0 deletions
|
|
@ -35,6 +35,7 @@ INSTALLED_APPS = [
|
|||
"django.contrib.sessions",
|
||||
"django.contrib.messages",
|
||||
"django.contrib.staticfiles",
|
||||
"flangr.posts",
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
|
@ -108,3 +109,5 @@ STATIC_URL = "static/"
|
|||
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
|
||||
|
||||
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
||||
|
||||
MEDIA_URL = "media/"
|
||||
|
|
|
|||
|
|
@ -15,3 +15,5 @@ DEBUG = True
|
|||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = "django-insecure-lt9sfgmvcrjuiz!=l)3f50x&333&p4wi60t1@jdjtrho43ytl+"
|
||||
|
||||
MEDIA_ROOT = "./media"
|
||||
|
|
|
|||
0
flangr/posts/__init__.py
Normal file
0
flangr/posts/__init__.py
Normal file
3
flangr/posts/admin.py
Normal file
3
flangr/posts/admin.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
6
flangr/posts/apps.py
Normal file
6
flangr/posts/apps.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class PostsConfig(AppConfig):
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "flangr.posts"
|
||||
32
flangr/posts/migrations/0001_initial.py
Normal file
32
flangr/posts/migrations/0001_initial.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
# Generated by Django 4.0.5 on 2022-07-03 21:35
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = []
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="Post",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("img", models.ImageField(upload_to="posts/%Y/%m")),
|
||||
("posted", models.DateTimeField(auto_now_add=True)),
|
||||
("public", models.BooleanField(default=False)),
|
||||
("title", models.CharField(max_length=255)),
|
||||
("body", models.TextField()),
|
||||
],
|
||||
),
|
||||
]
|
||||
0
flangr/posts/migrations/__init__.py
Normal file
0
flangr/posts/migrations/__init__.py
Normal file
15
flangr/posts/models.py
Normal file
15
flangr/posts/models.py
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
|
||||
|
||||
class Post(models.Model):
|
||||
img = models.ImageField(upload_to="posts/%Y/%m")
|
||||
posted = models.DateTimeField(auto_now_add=True)
|
||||
public = models.BooleanField(default=False)
|
||||
|
||||
title = models.CharField(max_length=255)
|
||||
body = models.TextField()
|
||||
|
||||
def __str__(self):
|
||||
return f"Post: {self.title} at {self.posted.strftime('%Y-%m-%d %H:%S')}"
|
||||
BIN
flangr/posts/test_data/test_img.png
Normal file
BIN
flangr/posts/test_data/test_img.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 320 B |
26
flangr/posts/tests.py
Normal file
26
flangr/posts/tests.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import os
|
||||
|
||||
from django.test import TestCase
|
||||
from django.core.files import File
|
||||
|
||||
from .models import Post
|
||||
|
||||
# Create your tests here.
|
||||
|
||||
|
||||
class TestPostModelTests(TestCase):
|
||||
def test_can_create_model(self):
|
||||
with open(
|
||||
os.path.join(os.path.dirname(__file__), "test_data", "test_img.png"),
|
||||
mode="rb",
|
||||
) as f:
|
||||
try:
|
||||
p = Post.objects.create(
|
||||
img=File(f, "somefile.png"),
|
||||
title="Foobar",
|
||||
body="Some file",
|
||||
)
|
||||
|
||||
self.assertIn("Foobar", str(p))
|
||||
finally:
|
||||
p.img.delete()
|
||||
3
flangr/posts/views.py
Normal file
3
flangr/posts/views.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
pillow
|
||||
django
|
||||
Loading…
Add table
Reference in a new issue