add - parent to org
This commit is contained in:
@@ -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 """
|
||||
|
||||
@@ -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'),
|
||||
),
|
||||
]
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user