add - parent to org

This commit is contained in:
2025-11-04 11:21:47 +03:30
parent 3c85d92c92
commit c2de185a26
3 changed files with 35 additions and 0 deletions

View File

@@ -203,12 +203,22 @@ class OrganizationTypeSerializer(serializers.ModelSerializer):
model = OrganizationType
fields = [
'id',
'parent',
'key',
'name',
'org_type_field',
'is_repeatable'
]
def to_representation(self, instance):
representation = super().to_representation(instance)
if instance.parent:
representation['parent'] = {
'name': instance.parent.name,
'id': instance.parent.id
}
class OrganizationSerializer(serializers.ModelSerializer):
""" Serialize organization data """

View File

@@ -0,0 +1,19 @@
# Generated by Django 5.0 on 2025-11-04 07:50
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('authentication', '0046_alter_organization_address'),
]
operations = [
migrations.AddField(
model_name='organizationtype',
name='parent',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='children', to='authentication.organizationtype'),
),
]

View File

@@ -82,6 +82,12 @@ class OrganizationType(BaseModel):
('CO', 'Cooperative'),
('CMP', 'Companies')
)
parent = models.ForeignKey(
'self',
on_delete=models.CASCADE,
related_name='children',
null=True
)
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)