Skip to content

Commit

Permalink
Merge pull request #5 from Abramov0Alexandr/feature
Browse files Browse the repository at this point in the history
Рефакторинг
  • Loading branch information
Abramov0Alexandr authored Sep 26, 2023
2 parents dd3506d + 501d4ba commit 86b399e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion custom_user/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

@admin.register(CustomUser)
class UserAdmin(admin.ModelAdmin):
list_display = ('email', 'first_name', 'last_name', 'is_seller', )
list_display = ('id', 'email', 'first_name', 'last_name', 'is_seller', )
list_display_links = ('email', )
list_filter = ('is_seller', )
5 changes: 2 additions & 3 deletions custom_user/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from django.contrib.auth.models import AbstractUser
from django.db import models

from custom_user.services import product_image_upload_path
from custom_user.services import shop_preview_upload_path
from custom_user.user_manager import CustomUserManager


Expand Down Expand Up @@ -32,7 +31,7 @@ class UserStatus(models.IntegerChoices):

# Поля, используемые для регистрации продавца
shop_name = models.CharField(max_length=200, verbose_name='Название магазина', **NULLABLE)
product_images = models.ImageField(upload_to=product_image_upload_path, verbose_name='Фото товара', **NULLABLE)
shop_preview = models.ImageField(upload_to=shop_preview_upload_path, verbose_name='Превью магазина', **NULLABLE)

# Общие поля для каждого вида пользователя
email = models.EmailField(unique=True, verbose_name='Email')
Expand Down
2 changes: 1 addition & 1 deletion custom_user/services.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
def product_image_upload_path(model, file) -> str:
def shop_preview_upload_path(model, file) -> str:
return f"product/{model.shop_name}/{file}"
10 changes: 8 additions & 2 deletions custom_user/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CustomersListView(generics.ListAPIView):
queryset = CustomUser.objects.all()
filter_backends = [DjangoFilterBackend]
filterset_fields = ('is_seller', )
permission_classes = IsAdminUser
permission_classes = [IsAdminUser]


class CustomerCreateView(generics.CreateAPIView):
Expand All @@ -39,9 +39,15 @@ def create(self, request, *args, **kwargs):
if is_seller:
# Если выбран статус продавца, устанавливаем его
serializer.save(is_seller=CustomUser.UserStatus.SELLER)
return Response(
{'message': 'Вы зарегистрированы в качестве продавца и можете размещать товары на площадке',
'shop_title': f'{serializer.data.get("shop_name")}',
'status': status.HTTP_201_CREATED})

else:
# Если выбран статус посетителя, оставляем его по умолчанию
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response({'message': 'Регистрация успешно завершена!',
'status': status.HTTP_201_CREATED})

return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

0 comments on commit 86b399e

Please sign in to comment.