Browse Source
feat(hadis): add gender option to Transmitters model, serializers, admin, and XMind view
feat(hadis): add gender option to Transmitters model, serializers, admin, and XMind view
- Add GenderChoices (male/female) field to Transmitters model with migration 0052 - Include gender across public and admin transmitter serializers - Expose gender in TransmittersAdmin filter and list display - Propagate transmitter gender in HadisCategoryXMindView flowchart payload - Add split_transmitters_gender management commandmaster
7 changed files with 84 additions and 8 deletions
-
6apps/hadis/admin/transmitter.py
-
40apps/hadis/management/commands/split_transmitters_gender.py
-
18apps/hadis/migrations/0052_transmitters_gender.py
-
10apps/hadis/models/transmitter.py
-
13apps/hadis/serializers/hadis.py
-
2apps/hadis/serializers/serializers_admin.py
-
3apps/hadis/views/category.py
@ -0,0 +1,40 @@ |
|||||
|
import random |
||||
|
from django.core.management.base import BaseCommand |
||||
|
from django.core.cache import cache |
||||
|
from apps.hadis.models import Transmitters |
||||
|
|
||||
|
|
||||
|
class Command(BaseCommand): |
||||
|
help = "Randomly split all existing Transmitters 50/50 between male and female for testing." |
||||
|
|
||||
|
def handle(self, *args, **options): |
||||
|
transmitters = list(Transmitters.objects.all().order_by("id")) |
||||
|
total = len(transmitters) |
||||
|
if total == 0: |
||||
|
self.stdout.write(self.style.WARNING("No transmitters found in the database.")) |
||||
|
return |
||||
|
|
||||
|
random.shuffle(transmitters) |
||||
|
half = total // 2 |
||||
|
|
||||
|
female_ids = [t.id for t in transmitters[:half]] |
||||
|
male_ids = [t.id for t in transmitters[half:]] |
||||
|
|
||||
|
female_updated = Transmitters.objects.filter(id__in=female_ids).update( |
||||
|
gender="female" |
||||
|
) |
||||
|
male_updated = Transmitters.objects.filter(id__in=male_ids).update( |
||||
|
gender="male" |
||||
|
) |
||||
|
|
||||
|
# Clear cache so XMind and sync endpoints reflect updated genders immediately |
||||
|
try: |
||||
|
cache.clear() |
||||
|
except Exception: |
||||
|
pass |
||||
|
|
||||
|
self.stdout.write( |
||||
|
self.style.SUCCESS( |
||||
|
f"Successfully updated {total} transmitters: {male_updated} male, {female_updated} female." |
||||
|
) |
||||
|
) |
||||
@ -0,0 +1,18 @@ |
|||||
|
# Generated by Django 4.2.30 on 2026-10-18 10:49 |
||||
|
|
||||
|
from django.db import migrations, models |
||||
|
|
||||
|
|
||||
|
class Migration(migrations.Migration): |
||||
|
|
||||
|
dependencies = [ |
||||
|
('hadis', '0051_add_category_is_topic'), |
||||
|
] |
||||
|
|
||||
|
operations = [ |
||||
|
migrations.AddField( |
||||
|
model_name='transmitters', |
||||
|
name='gender', |
||||
|
field=models.CharField(choices=[('male', 'Male'), ('female', 'Female')], default='male', max_length=10, verbose_name='Gender'), |
||||
|
), |
||||
|
] |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue