This commit is contained in:
root
2025-09-29 15:57:17 +03:00
commit 25e571d194
21 changed files with 370 additions and 0 deletions

0
articles/__init__.py Normal file
View File

7
articles/admin.py Normal file
View File

@@ -0,0 +1,7 @@
from django.contrib import admin
from .models import Article
class ArticleAdmin(admin.ModelAdmin):
list_display = ('title', 'author', 'get_excerpt', 'created_date')
admin.site.register(Article, ArticleAdmin)

6
articles/apps.py Normal file
View File

@@ -0,0 +1,6 @@
from django.apps import AppConfig
class ArticlesConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'articles'

View File

@@ -0,0 +1,27 @@
# Generated by Django 5.2.6 on 2025-09-29 11:59
import django.db.models.deletion
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='Article',
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.DateField(auto_now_add=True)),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]

View File

13
articles/models.py Normal file
View File

@@ -0,0 +1,13 @@
from django.db import models
from django.contrib.auth.models import User
class Article(models.Model):
title = models.CharField(max_length=200)
author = models.ForeignKey(User, on_delete=models.CASCADE)
text = models.TextField()
created_date = models.DateField(auto_now_add=True)
def __unicode__ (self):
return "%s: %s" % (self.author.username, self.title)
def get_excerpt(self):
return self.text[:200] + "..." if len(self.text) > 140 else self.text

BIN
articles/static/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 KiB

40
articles/static/index.css Normal file
View File

@@ -0,0 +1,40 @@
@import url('https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100..900;1,100..900&display=swap');
body {
background: #1e293b;
font-family: "Montserrat", sans-serif;
color: #f1f5f9;
}
a {
color: #7dd3fc;
}
.header {
display: flex;
gap: 10px;
max-width: 1200px;
margin: auto;
padding-left: 20px
}
.one-post {
background: #273449;
border: solid 1px #334155;
border-radius: 10px;
padding-left: 15px;
padding-right: 15px;
}
.article-created-date {
font-size: 12px;
}
.archive {
max-width: 1200px;
margin: auto;
display: grid;
padding: 20px;
gap: 20px;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

9
articles/static/logo.svg Normal file
View File

@@ -0,0 +1,9 @@
<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64" role="img" aria-labelledby="favtitle favdesc">
<title id="favtitle">IT лого (favicon)</title>
<desc id="favdesc">Иконка с угловыми скобками и диагональной линией.</desc>
<rect width="64" height="64" rx="12" fill="#0f172a"/>
<path d="M18 26 L10 32 L18 38" fill="none" stroke="#ffffff" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M46 26 L54 32 L46 38" fill="none" stroke="#ffffff" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M24 44 L40 20" stroke="#7dd3fc" stroke-width="3" stroke-linecap="round"/>
</svg>

After

Width:  |  Height:  |  Size: 708 B

View File

@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Архив статей</title>
{% load static %}
<link rel="stylesheet" href="{% static 'index.css' %}">
<link rel="shortcut icon" type="image/png" href="{% static 'favicon.ico' %}"/>
</head>
<body>
<div class="header">
<img src="{% static 'logo.svg' %}" />
<h1>Всё про IT</h1>
</div>
<div class="archive">
{% for post in posts %}
<div class="one-post">
<h2 class="post-title">{{ post.title }}</h2>
<div class="article-info">
<strong class="article-author">{{ post.author.first_name }}</strong>
<div class="article-created-date">{{ post.created_date }}</div>
</div>
<p class="article-text">{{ post.get_excerpt }}</p>
</div>
{% endfor %}
</div>
</body>
</html>

3
articles/tests.py Normal file
View File

@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

5
articles/views.py Normal file
View File

@@ -0,0 +1,5 @@
from .models import Article
from django.shortcuts import render
def archive(request):
return render(request, 'archive.html', {"posts": Article.objects.all()})