Skip to content

Commit

Permalink
Merge pull request #8 from Abramov0Alexandr/feature
Browse files Browse the repository at this point in the history
Создал приложение и модель Product
  • Loading branch information
Abramov0Alexandr authored Sep 26, 2023
2 parents 708b4bf + f33cea8 commit e6d375b
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 0 deletions.
Empty file added products/__init__.py
Empty file.
8 changes: 8 additions & 0 deletions products/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.contrib import admin
from products.models import Product


@admin.register(Product)
class UserAdmin(admin.ModelAdmin):
list_display = ('id', 'shop_name', 'product_title', 'seller', 'price', )
list_display_links = ('product_title', )
7 changes: 7 additions & 0 deletions products/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.apps import AppConfig


class ProductsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'products'
verbose_name = 'Товары'
Empty file added products/migrations/__init__.py
Empty file.
25 changes: 25 additions & 0 deletions products/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from django.contrib.auth import get_user_model
from django.db import models


class Product(models.Model):
"""
Модель для хранения информации о товаре.
"""

product_title = models.CharField(max_length=255, verbose_name='Наименование товара')
seller = models.ForeignKey(get_user_model(), on_delete=models.PROTECT, related_name='seller', verbose_name='Продавец')
price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='Цена товара')

objects = models.Manager

@property
def shop_name(self):
return self.seller.shop_name

def __str__(self):
return f'{self.product_title} {self.shop_name} {self.seller}'

class Meta:
verbose_name = 'Товар'
verbose_name_plural = 'Товары'
3 changes: 3 additions & 0 deletions products/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.

0 comments on commit e6d375b

Please sign in to comment.