diff --git a/core/__pycache__/admin.cpython-311.pyc b/core/__pycache__/admin.cpython-311.pyc index a5ed392..7913631 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 e061640..4563f36 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 5a69659..a19c8e4 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 2a36fd6..0b9d9db 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..2fbf728 100644 --- a/core/admin.py +++ b/core/admin.py @@ -1,3 +1,14 @@ from django.contrib import admin +from .models import Category, Product -# Register your models here. +@admin.register(Category) +class CategoryAdmin(admin.ModelAdmin): + list_display = ('name', 'slug') + prepopulated_fields = {'slug': ('name',)} + +@admin.register(Product) +class ProductAdmin(admin.ModelAdmin): + list_display = ('name', 'category', 'price', 'stock', 'is_active') + list_filter = ('category', 'is_active') + search_fields = ('name', 'description') + prepopulated_fields = {'slug': ('name',)} \ No newline at end of file diff --git a/core/migrations/0001_initial.py b/core/migrations/0001_initial.py new file mode 100644 index 0000000..cb1e883 --- /dev/null +++ b/core/migrations/0001_initial.py @@ -0,0 +1,43 @@ +# Generated by Django 5.2.7 on 2026-01-22 19:11 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + 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)), + ('slug', models.SlugField(blank=True, unique=True)), + ('description', models.TextField(blank=True)), + ('image_url', models.URLField(blank=True, help_text='Placeholder image URL')), + ], + options={ + 'verbose_name_plural': 'Categories', + }, + ), + migrations.CreateModel( + name='Product', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=200)), + ('slug', models.SlugField(blank=True, unique=True)), + ('description', models.TextField()), + ('price', models.DecimalField(decimal_places=2, max_digits=10)), + ('stock', models.PositiveIntegerField(default=0)), + ('image_url', models.URLField(blank=True, help_text='Placeholder image URL')), + ('is_active', models.BooleanField(default=True)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='products', 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..5de0a98 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..5195e91 100644 --- a/core/models.py +++ b/core/models.py @@ -1,3 +1,38 @@ from django.db import models +from django.utils.text import slugify -# Create your models here. +class Category(models.Model): + name = models.CharField(max_length=100) + slug = models.SlugField(unique=True, blank=True) + description = models.TextField(blank=True) + image_url = models.URLField(blank=True, help_text="Placeholder image URL") + + def save(self, *args, **kwargs): + if not self.slug: + self.slug = slugify(self.name) + super().save(*args, **kwargs) + + def __str__(self): + return self.name + + class Meta: + verbose_name_plural = "Categories" + +class Product(models.Model): + category = models.ForeignKey(Category, related_name='products', on_delete=models.CASCADE) + name = models.CharField(max_length=200) + slug = models.SlugField(unique=True, blank=True) + description = models.TextField() + price = models.DecimalField(max_digits=10, decimal_places=2) + stock = models.PositiveIntegerField(default=0) + image_url = models.URLField(blank=True, help_text="Placeholder image URL") + is_active = models.BooleanField(default=True) + created_at = models.DateTimeField(auto_now_add=True) + + def save(self, *args, **kwargs): + if not self.slug: + self.slug = slugify(self.name) + super().save(*args, **kwargs) + + def __str__(self): + return self.name \ No newline at end of file diff --git a/core/templates/base.html b/core/templates/base.html index 1e7e5fb..c27fce9 100644 --- a/core/templates/base.html +++ b/core/templates/base.html @@ -1,25 +1,103 @@ +{% load static %} -
- -