From b914efd1fb56415a69451b21dff3418e5ff72714 Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Tue, 28 Oct 2025 16:48:19 +0330 Subject: [PATCH] add org_type_field to oragnization type serializer --- .../api/v1/serializers/serializer.py | 5 +++++ .../0040_organizationtype_org_type_field.py | 18 ++++++++++++++++++ apps/authentication/models.py | 5 +++++ logs/django_requests.log | 7 +++++++ 4 files changed, 35 insertions(+) create mode 100644 apps/authentication/migrations/0040_organizationtype_org_type_field.py diff --git a/apps/authentication/api/v1/serializers/serializer.py b/apps/authentication/api/v1/serializers/serializer.py index 1428157..02c3fc6 100644 --- a/apps/authentication/api/v1/serializers/serializer.py +++ b/apps/authentication/api/v1/serializers/serializer.py @@ -203,6 +203,7 @@ class OrganizationTypeSerializer(serializers.ModelSerializer): 'id', 'key', 'name', + 'org_type_field', ] @@ -225,6 +226,10 @@ class OrganizationSerializer(serializers.ModelSerializer): extra_kwargs = {} def validate(self, attrs): + """ + @ validate national_unique_code to be unique + @ validate to organization type field + """ national_unique_id = self.context['request'].data['organization']['national_unique_id'] if not self.instance: diff --git a/apps/authentication/migrations/0040_organizationtype_org_type_field.py b/apps/authentication/migrations/0040_organizationtype_org_type_field.py new file mode 100644 index 0000000..84f0d5f --- /dev/null +++ b/apps/authentication/migrations/0040_organizationtype_org_type_field.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0 on 2025-10-28 12:25 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('authentication', '0039_remove_organizationtype_region_scope'), + ] + + operations = [ + migrations.AddField( + model_name='organizationtype', + name='org_type_field', + field=models.CharField(choices=[('CI', 'city'), ('CO', 'country'), ('PR', 'province')], max_length=25, null=True), + ), + ] diff --git a/apps/authentication/models.py b/apps/authentication/models.py index 589c806..86f5424 100644 --- a/apps/authentication/models.py +++ b/apps/authentication/models.py @@ -85,6 +85,11 @@ class OrganizationType(BaseModel): key = models.CharField(choices=organization_keys, default='EMP', max_length=3) name = models.CharField(max_length=50, unique=True, null=True) code = models.IntegerField(default=0) + org_type_field = models.CharField(choices=[ + ('CI', 'city'), + ('CO', 'country'), + ('PR', 'province'), + ], max_length=25, null=True) def __str__(self): return f'{self.key}-{self.name}' diff --git a/logs/django_requests.log b/logs/django_requests.log index 8592db6..3eaa434 100644 --- a/logs/django_requests.log +++ b/logs/django_requests.log @@ -323,3 +323,10 @@ django.core.exceptions.FieldError: Unsupported lookup 'name' for ForeignKey or j [2025-10-28 14:35:00,268] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\core\api.py changed, reloading. [2025-10-28 14:35:02,391] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader [2025-10-28 14:55:17,922] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authentication\api\v1\api.py changed, reloading. +[2025-10-28 14:55:20,845] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-10-28 15:54:52,304] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authentication\models.py changed, reloading. +[2025-10-28 15:54:54,375] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-10-28 16:04:05,601] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authentication\api\v1\serializers\serializer.py changed, reloading. +[2025-10-28 16:04:07,708] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-10-28 16:46:52,938] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authentication\api\v1\serializers\serializer.py changed, reloading. +[2025-10-28 16:46:57,388] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader