pylance fixes
This commit is contained in:
@@ -185,15 +185,25 @@ class ChangeUserMembership(ViewSet):
|
||||
user = request.user
|
||||
user_profile = get_object_or_404(UserProfile, user=user)
|
||||
|
||||
# преобразуем plan в account_type если нужно
|
||||
# преобразуем plan в account_type
|
||||
if 'plan' in request.data and 'account_type' not in request.data:
|
||||
request.data['account_type'] = request.data['plan']
|
||||
|
||||
if 'account_type' not in request.data:
|
||||
return Response({
|
||||
"error": "Не указан тарифный план",
|
||||
"details": "Необходимо указать plan или account_type"
|
||||
}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
serializer = PlanChangeSerializer(user_profile, data=request.data)
|
||||
|
||||
if serializer.is_valid():
|
||||
# получаем объект тарифного плана
|
||||
new_plan = get_object_or_404(Pricing, plan=serializer.validated_data['account_type'])
|
||||
try:
|
||||
if not serializer.is_valid():
|
||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
account_type = request.data['account_type']
|
||||
# получаем тарифный план
|
||||
new_plan = get_object_or_404(Pricing, plan=account_type)
|
||||
|
||||
# создаем транзакцию
|
||||
transaction = Transactions.objects.create(
|
||||
@@ -208,8 +218,14 @@ class ChangeUserMembership(ViewSet):
|
||||
serializer.save()
|
||||
return Response({
|
||||
"message": "Тариф успешно изменен",
|
||||
"account_type": serializer.validated_data['account_type']
|
||||
"account_type": new_plan.plan
|
||||
}, status=status.HTTP_200_OK)
|
||||
|
||||
except Exception as e:
|
||||
return Response({
|
||||
"error": "Ошибка при изменении тарифного плана",
|
||||
"details": str(e)
|
||||
}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
|
||||
@@ -15,3 +15,4 @@ class PricingAdmin(admin.ModelAdmin):
|
||||
|
||||
admin.site.register(FAQ)
|
||||
admin.site.register(News)
|
||||
admin.site.register(Transactions)
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.2.1 on 2025-05-30 11:30
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('sitemanagement', '0018_alter_pricing_highlight_limit_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='transactions',
|
||||
name='created_at',
|
||||
field=models.DateTimeField(auto_now_add=True, choices=[('success', 'Успешно'), ('failed', 'Отклонено')], verbose_name='Дата создания'),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,23 @@
|
||||
# Generated by Django 5.2.1 on 2025-05-30 15:13
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('sitemanagement', '0019_alter_transactions_created_at'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='transactions',
|
||||
name='created_at',
|
||||
field=models.DateTimeField(auto_now_add=True, verbose_name='Дата создания'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='transactions',
|
||||
name='status',
|
||||
field=models.CharField(choices=[('success', 'Успешно'), ('failed', 'Отклонено')], max_length=255, verbose_name='Статус'),
|
||||
),
|
||||
]
|
||||
@@ -91,7 +91,7 @@ class Transactions(models.Model):
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='Пользователь')
|
||||
amount = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='Сумма')
|
||||
plan = models.ForeignKey(Pricing, on_delete=models.CASCADE, verbose_name='Тарифный план')
|
||||
status = models.CharField(max_length=255, verbose_name='Статус')
|
||||
status = models.CharField(max_length=255, verbose_name='Статус', choices=[('success', 'Успешно'), ('failed', 'Отклонено')])
|
||||
created_at = models.DateTimeField(auto_now_add=True, verbose_name='Дата создания')
|
||||
|
||||
class Meta:
|
||||
|
||||
Reference in New Issue
Block a user