diff --git a/assets/pasted-20251029-002142-3359b288.png b/assets/pasted-20251029-002142-3359b288.png new file mode 100644 index 0000000..f0faf7d Binary files /dev/null and b/assets/pasted-20251029-002142-3359b288.png differ diff --git a/assets/pasted-20251029-002338-2cd3d3b2.png b/assets/pasted-20251029-002338-2cd3d3b2.png new file mode 100644 index 0000000..87d0c90 Binary files /dev/null and b/assets/pasted-20251029-002338-2cd3d3b2.png differ diff --git a/assets/pasted-20251029-003217-94e2da6f.png b/assets/pasted-20251029-003217-94e2da6f.png new file mode 100644 index 0000000..e63eb1b Binary files /dev/null and b/assets/pasted-20251029-003217-94e2da6f.png differ diff --git a/assets/vm-shot-2025-10-29T00-20-57-673Z.jpg b/assets/vm-shot-2025-10-29T00-20-57-673Z.jpg new file mode 100644 index 0000000..9c1042b Binary files /dev/null and b/assets/vm-shot-2025-10-29T00-20-57-673Z.jpg differ diff --git a/config/__pycache__/urls.cpython-311.pyc b/config/__pycache__/urls.cpython-311.pyc index 139db10..aeaeaf4 100644 Binary files a/config/__pycache__/urls.cpython-311.pyc and b/config/__pycache__/urls.cpython-311.pyc differ diff --git a/config/urls.py b/config/urls.py index 5093d47..061dcf7 100644 --- a/config/urls.py +++ b/config/urls.py @@ -16,8 +16,14 @@ Including another URLconf """ from django.contrib import admin from django.urls import include, path +from django.conf import settings +from django.contrib.staticfiles.urls import staticfiles_urlpatterns +from django.conf.urls.static import static urlpatterns = [ path("admin/", admin.site.urls), path("", include("core.urls")), ] + +if settings.DEBUG: + urlpatterns += staticfiles_urlpatterns() diff --git a/core/__pycache__/admin.cpython-311.pyc b/core/__pycache__/admin.cpython-311.pyc index cd6f855..c04c091 100644 Binary files a/core/__pycache__/admin.cpython-311.pyc and b/core/__pycache__/admin.cpython-311.pyc differ diff --git a/core/__pycache__/models.cpython-311.pyc b/core/__pycache__/models.cpython-311.pyc index 9aa598b..2cdbd65 100644 Binary files a/core/__pycache__/models.cpython-311.pyc and b/core/__pycache__/models.cpython-311.pyc differ diff --git a/core/__pycache__/urls.cpython-311.pyc b/core/__pycache__/urls.cpython-311.pyc index 1f807fa..3e116ea 100644 Binary files a/core/__pycache__/urls.cpython-311.pyc and b/core/__pycache__/urls.cpython-311.pyc differ diff --git a/core/__pycache__/views.cpython-311.pyc b/core/__pycache__/views.cpython-311.pyc index 6867ddf..17db810 100644 Binary files a/core/__pycache__/views.cpython-311.pyc and b/core/__pycache__/views.cpython-311.pyc differ diff --git a/core/admin.py b/core/admin.py index 8c38f3f..a756890 100644 --- a/core/admin.py +++ b/core/admin.py @@ -1,3 +1,15 @@ from django.contrib import admin +from .models import Category, Article -# Register your models here. + +@admin.register(Category) +class CategoryAdmin(admin.ModelAdmin): + list_display = ('name', 'slug') + prepopulated_fields = {'slug': ('name',)} + + +@admin.register(Article) +class ArticleAdmin(admin.ModelAdmin): + list_display = ('title', 'category', 'author', 'created_at') + list_filter = ('category', 'author') + search_fields = ('title', 'content') \ No newline at end of file diff --git a/core/management/commands/__pycache__/populate_db.cpython-311.pyc b/core/management/commands/__pycache__/populate_db.cpython-311.pyc new file mode 100644 index 0000000..b24b4ca Binary files /dev/null and b/core/management/commands/__pycache__/populate_db.cpython-311.pyc differ diff --git a/core/management/commands/populate_db.py b/core/management/commands/populate_db.py new file mode 100644 index 0000000..4a17c8f --- /dev/null +++ b/core/management/commands/populate_db.py @@ -0,0 +1,38 @@ +from django.core.management.base import BaseCommand +from django.contrib.auth.models import User +from core.models import Category, Article + +class Command(BaseCommand): + help = 'Populates the database with sample data' + + def handle(self, *args, **options): + self.stdout.write('Deleting existing data...') + Article.objects.all().delete() + Category.objects.all().delete() + User.objects.filter(is_superuser=False).delete() + + self.stdout.write('Creating new data...') + + # Create users + editor_user = User.objects.create_user(username='editor', password='password') + + # Create categories + general_cat = Category.objects.create(name='General', slug='general') + tech_cat = Category.objects.create(name='Technical', slug='technical') + + # Create articles + Article.objects.create( + title='Getting Started with Django', + content='This is a beginner-friendly guide to start your journey with the Django framework.', + category=tech_cat, + author=editor_user + ) + + Article.objects.create( + title='Our Company Policy', + content='An overview of our company policies and guidelines for all employees.', + category=general_cat, + author=editor_user + ) + + self.stdout.write(self.style.SUCCESS('Successfully populated the database.')) diff --git a/core/migrations/0001_initial.py b/core/migrations/0001_initial.py new file mode 100644 index 0000000..262fdfe --- /dev/null +++ b/core/migrations/0001_initial.py @@ -0,0 +1,37 @@ +# Generated by Django 5.2.7 on 2025-10-29 00:16 + +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='Category', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=100, unique=True)), + ('slug', models.SlugField(max_length=100, unique=True)), + ], + ), + 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)), + ('content', models.TextField()), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='articles', to=settings.AUTH_USER_MODEL)), + ('category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='articles', to='core.category')), + ], + ), + ] diff --git a/core/migrations/__pycache__/0001_initial.cpython-311.pyc b/core/migrations/__pycache__/0001_initial.cpython-311.pyc new file mode 100644 index 0000000..5323418 Binary files /dev/null and b/core/migrations/__pycache__/0001_initial.cpython-311.pyc differ diff --git a/core/models.py b/core/models.py index 71a8362..efba32c 100644 --- a/core/models.py +++ b/core/models.py @@ -1,3 +1,22 @@ from django.db import models +from django.contrib.auth.models import User -# Create your models here. + +class Category(models.Model): + name = models.CharField(max_length=100, unique=True) + slug = models.SlugField(max_length=100, unique=True) + + def __str__(self): + return self.name + + +class Article(models.Model): + title = models.CharField(max_length=200) + content = models.TextField() + category = models.ForeignKey(Category, on_delete=models.CASCADE, related_name='articles') + author = models.ForeignKey(User, on_delete=models.CASCADE, related_name='articles') + created_at = models.DateTimeField(auto_now_add=True) + updated_at = models.DateTimeField(auto_now=True) + + def __str__(self): + return self.title \ No newline at end of file diff --git a/core/templates/base.html b/core/templates/base.html index 788576e..9cc8059 100644 --- a/core/templates/base.html +++ b/core/templates/base.html @@ -1,11 +1,35 @@ +{% load static %} -
+ -