-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from Abramov0Alexandr/feature
Создал приложение и модель Product
- Loading branch information
Showing
6 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = 'Товары' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |