supportda tuman requireddan olib tashlandi
This commit is contained in:
@@ -19,7 +19,7 @@ class SupportListSerializer(serializers.ModelSerializer):
|
||||
return {
|
||||
'id': obj.district.id,
|
||||
'name': obj.district.name,
|
||||
}
|
||||
} if obj.district else None
|
||||
|
||||
def get_user(self, obj):
|
||||
return {
|
||||
|
||||
19
core/apps/shared/migrations/0017_alter_support_district.py
Normal file
19
core/apps/shared/migrations/0017_alter_support_district.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# Generated by Django 5.2 on 2025-12-04 12:35
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('shared', '0016_plan_comment_plan_doctor_plan_extra_location_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='support',
|
||||
name='district',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='supports', to='shared.district'),
|
||||
),
|
||||
]
|
||||
@@ -13,7 +13,13 @@ class Support(BaseModel):
|
||||
('HELP', 'yordam'),
|
||||
)
|
||||
|
||||
district = models.ForeignKey(District, on_delete=models.CASCADE, related_name='supports')
|
||||
district = models.ForeignKey(
|
||||
District,
|
||||
on_delete=models.SET_NULL,
|
||||
related_name='supports',
|
||||
blank=True,
|
||||
null=True
|
||||
)
|
||||
problem = models.TextField()
|
||||
date = models.DateField()
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='supports')
|
||||
|
||||
@@ -9,12 +9,13 @@ from core.apps.shared.models import Support, District
|
||||
|
||||
|
||||
class SupportCreateSerializer(serializers.Serializer):
|
||||
district_id = serializers.IntegerField()
|
||||
district_id = serializers.IntegerField(required=False)
|
||||
problem = serializers.CharField()
|
||||
date = serializers.DateField()
|
||||
type = serializers.ChoiceField(choices=Support.TYPE)
|
||||
|
||||
def validate(self, data):
|
||||
if data.get('district_id'):
|
||||
district = District.objects.filter(id=data['district_id']).first()
|
||||
if not district:
|
||||
raise serializers.ValidationError({'district': "district not found"})
|
||||
|
||||
Reference in New Issue
Block a user