From 708f4032caabffe908a1ce7cc3015e0b9c43e09c Mon Sep 17 00:00:00 2001 From: behruz-dev Date: Thu, 27 Nov 2025 15:03:39 +0500 Subject: [PATCH] tour plan uchun ikkita yangi field qoshildi --- core/apps/shared/admin/tour_plan.py | 2 +- ...istrict_tourplan_location_send_and_more.py | 27 +++++++++++++++++++ core/apps/shared/models/tour_plan.py | 10 +++++-- core/apps/shared/serializers/tour_plan.py | 10 ++----- 4 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 core/apps/shared/migrations/0009_remove_tourplan_district_tourplan_location_send_and_more.py diff --git a/core/apps/shared/admin/tour_plan.py b/core/apps/shared/admin/tour_plan.py index b966855..70093e6 100644 --- a/core/apps/shared/admin/tour_plan.py +++ b/core/apps/shared/admin/tour_plan.py @@ -6,5 +6,5 @@ from core.apps.shared.models import TourPlan @admin.register(TourPlan) class TourPlanAdmin(admin.ModelAdmin): - list_display = ['id', 'district', 'longitude', 'latitude', 'user'] + list_display = ['id', 'place_name', 'longitude', 'latitude', 'user'] \ No newline at end of file diff --git a/core/apps/shared/migrations/0009_remove_tourplan_district_tourplan_location_send_and_more.py b/core/apps/shared/migrations/0009_remove_tourplan_district_tourplan_location_send_and_more.py new file mode 100644 index 0000000..610170c --- /dev/null +++ b/core/apps/shared/migrations/0009_remove_tourplan_district_tourplan_location_send_and_more.py @@ -0,0 +1,27 @@ +# Generated by Django 5.2 on 2025-11-27 10:02 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('shared', '0008_rename_langitude_location_latitude_and_more'), + ] + + operations = [ + migrations.RemoveField( + model_name='tourplan', + name='district', + ), + migrations.AddField( + model_name='tourplan', + name='location_send', + field=models.BooleanField(default=False), + ), + migrations.AddField( + model_name='tourplan', + name='place_name', + field=models.CharField(max_length=200, null=True), + ), + ] diff --git a/core/apps/shared/models/tour_plan.py b/core/apps/shared/models/tour_plan.py index 18cfcef..c7ecff9 100644 --- a/core/apps/shared/models/tour_plan.py +++ b/core/apps/shared/models/tour_plan.py @@ -7,11 +7,17 @@ from core.apps.accounts.models import User class TourPlan(BaseModel): - district = models.ForeignKey(District, on_delete=models.CASCADE, related_name='tour_plans') + place_name = models.CharField(max_length=200, null=True) user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='tour_plans') latitude = models.FloatField(null=True, blank=True) longitude = models.FloatField(null=True, blank=True) + location_send = models.BooleanField(default=False) def __str__(self): - return f"{self.user.first_name}'s tour plan to {self.district.name}" \ No newline at end of file + return f"{self.user.first_name}'s tour plan to {self.district.name}" + + def save(self, *args, **kwargs): + if self.longitude and self.latitude: + self.location_send = True + return super().save(*args, **kwargs) \ No newline at end of file diff --git a/core/apps/shared/serializers/tour_plan.py b/core/apps/shared/serializers/tour_plan.py index 03fbc13..725d957 100644 --- a/core/apps/shared/serializers/tour_plan.py +++ b/core/apps/shared/serializers/tour_plan.py @@ -11,11 +11,5 @@ class TourPlanSerializer(serializers.ModelSerializer): class Meta: model = TourPlan fields = [ - 'id', 'district', 'longitude', 'latitude', 'created_at' - ] - - def get_district(self, obj): - return { - 'id': obj.district.id, - 'name': obj.district.name, - } \ No newline at end of file + 'id', 'place_name', 'longitude', 'latitude', 'location_send', 'created_at' + ] \ No newline at end of file