diff --git a/custom_user/admin.py b/custom_user/admin.py index b4ca11c..a7c0832 100644 --- a/custom_user/admin.py +++ b/custom_user/admin.py @@ -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', ) diff --git a/custom_user/models.py b/custom_user/models.py index 068bb6e..c139f10 100644 --- a/custom_user/models.py +++ b/custom_user/models.py @@ -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 @@ -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') diff --git a/custom_user/services.py b/custom_user/services.py index 9d6b62c..b596dca 100644 --- a/custom_user/services.py +++ b/custom_user/services.py @@ -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}" diff --git a/custom_user/views.py b/custom_user/views.py index 348a31b..b6fd7bb 100644 --- a/custom_user/views.py +++ b/custom_user/views.py @@ -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): @@ -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)