Skip to content

Commit

Permalink
Merge pull request #26 from healthy-food-and-dietary-products/feature…
Browse files Browse the repository at this point in the history
…/orders_api

Feature/orders api
  • Loading branch information
earlinn authored Oct 23, 2023
2 parents fdd7a72 + 3e14a9c commit 9fad6bc
Show file tree
Hide file tree
Showing 12 changed files with 368 additions and 86 deletions.
13 changes: 13 additions & 0 deletions backend/api/permissions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from rest_framework import permissions


class IsAuthorOnly(permissions.BasePermission):
"""Only Author has permissions."""

def has_permission(self, request, view):
return (
request.method in permissions.SAFE_METHODS and request.user.is_authenticated
)

def has_object_permission(self, request, view, obj):
return obj.user == request.user
1 change: 1 addition & 0 deletions backend/data/category.csv
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ id,name,slug
7,Безлактозные продукты,lactose-free
8,Мясная продукция,meat
9,Птица,poultry
10,Орехи,nuts
22 changes: 22 additions & 0 deletions backend/data/components.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
id,name
1,Авокадо
2,Яблоко
3,Пшеничная Мука высший сорт
4,Ржаная Мука
5,Дрожжи хлебопекарные
6,Яйца
7,Яичный порошок
8,Огурцы
9,Соль
10,Зеленый чай
11,Черный чай
12,Молоко
13,Творог
14,Сливочное Масло
15,Оливковое масло
16,Зерновые хлопья
17,Мюсли
18,Бананы
19,Груши
20,Сливы,
21,Сахар
5 changes: 5 additions & 0 deletions backend/data/producer.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
id,name,producer_type,description,address
1,Курочкин П. Н.,Индивидуальный предприниматель,Торговля молочными продуктами,Москва
2,Веселый молочник,Юридическое лицо,Торговля молочными продуктами,Тверь
3,Выборжец,Юридическое лицо,Фрукты и овощи круглый год,Ленинградская область
4,Хлебный дом,Юридическое лицо,Хлебобулочные изделия и выпечка,Санкт-Петербург
9 changes: 9 additions & 0 deletions backend/data/subcategory.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
id,parent_category_id,name,slug
1,3,Ржаной хлеб,rye_bread
2,3,Хлебцы зерновые,grain_loaves
3,4,Чай черный,black_tea
4,4,Чай зеленый,green_tea
5,6,Хлебцы безглютеновые,gluten-free_loaves
6,6,Печенье безглютеновое,gluten-free_cookies
7,7,Молоко без лактозы,lactose-free_milk
8,2,Зеленые овощи,fruts
6 changes: 6 additions & 0 deletions backend/data/tags.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
id,name,slug
1,Детям,kids
2,Диабет,diabetes
3,Мало калорий,min_calories
4,Сытно,hearty
5,Витамины,vitamins
10 changes: 5 additions & 5 deletions backend/data/users.csv
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
id,username,email,password,first_name,last_name,address
2,vasya.pupkin,vasya@yandex.ru,Qwerty123poiu,Вася,Пупкин,Saint-Petersburg
3,july.kol,kolkinaa@mail.ru,mnbvcxz12345,Юля,Колкина,Saint-Petersburg
4,nastya.vasina,nastya@yandex.ru,1234Qwerty987,Настя,Васина,Saint-Petersburg
5,kisa.mura,kisa@yandex.ru,mnjggffdfdf,Кира,Муравьева,Saint-Petersburg
id,username,email,password,first_name,last_name,city,address
2,vasya.pupkin,vasya@yandex.ru,Qwerty123poiu,Вася,Пупкин,Saint-Petersburg,ул.Брянцева д.4 кв18
3,july.kol,kolkinaa@mail.ru,mnbvcxz12345,Юля,Колкина,Saint-Petersburg,канал Грибоедова д.6 кв 11
4,nastya.vasina,nastya@yandex.ru,1234Qwerty987,Настя,Васина,Saint-Petersburg,Московский проспект д. 5 кв 98
5,kisa.mura,kisa@yandex.ru,mnjggffdfdf,Кира,Муравьева,Saint-Petersburg,Василеостровская д.7 кв 3
6,Kostya.Smirny,smirnov@yandex.ru,smirnuy098876,Константин,Смирнов,Saint-Petersburg
7,sonya.and,andr@mail.ru,andr0987,Соня,Андреева,Saint-Petersburg
33 changes: 23 additions & 10 deletions backend/orders/admin.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,46 @@
from django.contrib import admin

from orders.models import Order, ShoppingCart
from orders.models import Order, ShoppingCart, ShoppingCartProduct


class ShoppingCartProductInline(admin.TabularInline):
model = ShoppingCartProduct
list_display = ("id", "product", "quantity")
list_editable = ("product", "quantity")


@admin.register(ShoppingCart)
class ShoppingCartAdmin(admin.ModelAdmin):
list_display = ("id", "user", "product", "quantity", "status")
list_editable = ("user", "product", "quantity")
search_fields = ("user",)
inlines = (ShoppingCartProductInline,)
list_display = (
"id",
"user",
"status",
)
list_editable = ("status",)
list_filter = ("user", "status")


@admin.register(Order)
class OrderAdmin(admin.ModelAdmin):
list_display = (
"id",
"user",
"goods",
"date",
"order_number",
"shopping_cart",
"ordering_date",
"status",
"payment_method",
"is_paid",
"delivery_method",
"comment",
"total_price",
"address",
"package",
)
list_editable = (
"status",
"payment_method",
"is_paid",
"comment",
"delivery_method",
"address",
"package",
)
list_filter = ("ordering_date", "order_number")
124 changes: 87 additions & 37 deletions backend/orders/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Generated by Django 4.2.6 on 2023-10-19 14:43
# Generated by Django 4.2.6 on 2023-10-23 06:22

import django.core.validators
import django.db.models.deletion
from django.conf import settings
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
Expand All @@ -12,6 +12,7 @@ class Migration(migrations.Migration):
dependencies = [
("products", "0001_initial"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("users", "0001_initial"),
]

operations = [
Expand All @@ -27,20 +28,6 @@ class Migration(migrations.Migration):
verbose_name="ID",
),
),
(
"quantity",
models.IntegerField(
validators=[
django.core.validators.MinValueValidator(
1, "Разрешены значения от 1 до 100"
),
django.core.validators.MaxValueValidator(
10000, "Разрешены значения от 1 до 100"
),
],
verbose_name="Количество товара",
),
),
(
"status",
models.CharField(
Expand All @@ -52,30 +39,82 @@ class Migration(migrations.Migration):
max_length=50,
),
),
],
options={
"verbose_name": "Корзина",
"verbose_name_plural": "Корзина",
},
),
migrations.CreateModel(
name="ShoppingCartProduct",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"quantity",
models.PositiveIntegerField(
default=1,
validators=[
django.core.validators.MinValueValidator(
1, "Разрешены значения от 1 до 10000"
),
django.core.validators.MaxValueValidator(
10000, "Разрешены значения от 1 до 10000"
),
],
verbose_name="Количество",
),
),
(
"product",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="shopping_carts",
related_name="products",
to="products.product",
verbose_name="Продукт в корзине",
),
),
(
"user",
"shopping_cart",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="shopping_carts",
to=settings.AUTH_USER_MODEL,
verbose_name="Добавил в корзину",
to="orders.shoppingcart",
verbose_name="Корзина",
),
),
],
options={
"verbose_name": "Корзина",
"verbose_name_plural": "Корзина",
"verbose_name": "Продукты в корзине",
"verbose_name_plural": "Продукты в корзине",
},
),
migrations.AddField(
model_name="shoppingcart",
name="products",
field=models.ManyToManyField(
through="orders.ShoppingCartProduct",
to="products.product",
verbose_name="Продукты в корзине",
),
),
migrations.AddField(
model_name="shoppingcart",
name="user",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="orders",
to=settings.AUTH_USER_MODEL,
verbose_name="Покупатель",
),
),
migrations.CreateModel(
name="Order",
fields=[
Expand All @@ -89,8 +128,16 @@ class Migration(migrations.Migration):
),
),
(
"date",
models.DateField(auto_now_add=True, verbose_name="Дата оформления"),
"order_number",
models.PositiveIntegerField(
auto_created=True, verbose_name="Номер заказа"
),
),
(
"ordering_date",
models.DateTimeField(
auto_now_add=True, verbose_name="Дата оформления заказа"
),
),
(
"status",
Expand All @@ -114,7 +161,7 @@ class Migration(migrations.Migration):
choices=[
("Cash", "Наличные"),
("By card on the website", "Картой на сайте"),
("In getting", "При получении"),
("In getting by card", "Оплата картой курьеру"),
],
default="Картой на сайте",
max_length=50,
Expand All @@ -133,36 +180,39 @@ class Migration(migrations.Migration):
max_length=50,
),
),
("total_price", models.IntegerField(default=0)),
(
"goods",
"package",
models.BooleanField(default=False, verbose_name="Упаковка"),
),
(
"address",
models.ForeignKey(
blank=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="orders",
to="orders.shoppingcart",
verbose_name="Покупки",
to="users.address",
verbose_name="Адрес покупателя",
),
),
(
"user",
"shopping_cart",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="orders",
to=settings.AUTH_USER_MODEL,
verbose_name="Покупатель",
to="orders.shoppingcart",
),
),
],
options={
"verbose_name": "Заказ",
"verbose_name_plural": "Заказы",
"ordering": ["-date"],
"ordering": ["-ordering_date"],
},
),
migrations.AddConstraint(
model_name="shoppingcart",
model_name="shoppingcartproduct",
constraint=models.UniqueConstraint(
fields=("user", "product"), name="unique_shopping_cart"
fields=("shopping_cart", "product"),
name="unique_shopping_cart_products",
),
),
]
25 changes: 25 additions & 0 deletions backend/orders/migrations/0002_alter_order_address.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 4.2.6 on 2023-10-23 09:41

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
dependencies = [
("users", "0001_initial"),
("orders", "0001_initial"),
]

operations = [
migrations.AlterField(
model_name="order",
name="address",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
to="users.address",
verbose_name="Адрес покупателя",
),
),
]
Loading

0 comments on commit 9fad6bc

Please sign in to comment.