From 3c7dcb4c5142560fa2c36151f6efbe42d78fb77f Mon Sep 17 00:00:00 2001 From: moanos Date: Tue, 31 Dec 2024 13:47:31 +0100 Subject: [PATCH] feat: Allow location to be null in SearchSubscription --- ...er_searchsubscription_location_and_more.py | 24 +++++++++++++++++++ src/fellchensammlung/models.py | 9 ++++--- 2 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 src/fellchensammlung/migrations/0031_alter_searchsubscription_location_and_more.py diff --git a/src/fellchensammlung/migrations/0031_alter_searchsubscription_location_and_more.py b/src/fellchensammlung/migrations/0031_alter_searchsubscription_location_and_more.py new file mode 100644 index 0000000..5a115d2 --- /dev/null +++ b/src/fellchensammlung/migrations/0031_alter_searchsubscription_location_and_more.py @@ -0,0 +1,24 @@ +# Generated by Django 5.1.4 on 2024-12-31 12:42 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('fellchensammlung', '0030_rename_radius_searchsubscription_max_distance'), + ] + + operations = [ + migrations.AlterField( + model_name='searchsubscription', + name='location', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to='fellchensammlung.location'), + ), + migrations.AlterField( + model_name='searchsubscription', + name='max_distance', + field=models.IntegerField(choices=[(20, '20 km'), (50, '50 km'), (100, '100 km'), (200, '200 km'), (500, '500 km')], null=True), + ), + ] diff --git a/src/fellchensammlung/models.py b/src/fellchensammlung/models.py index 86087cb..8fcaac6 100644 --- a/src/fellchensammlung/models.py +++ b/src/fellchensammlung/models.py @@ -559,12 +559,15 @@ class SearchSubscription(models.Model): - For matches: Send notification to user of the SearchSubscription """ owner = models.ForeignKey(User, on_delete=models.CASCADE) - location = models.ForeignKey(Location, on_delete=models.PROTECT) + location = models.ForeignKey(Location, on_delete=models.PROTECT, null=True) sex = models.CharField(max_length=20, choices=SexChoicesWithAll.choices) - max_distance = models.IntegerField(choices=DistanceChoices.choices) + max_distance = models.IntegerField(choices=DistanceChoices.choices, null=True) def __str__(self): - return f"{self.owner}: [{SexChoicesWithAll(self.sex).label}] {self.max_distance}km - {self.location}" + if self.location and self.max_distance: + return f"{self.owner}: [{SexChoicesWithAll(self.sex).label}] {self.max_distance}km - {self.location}" + else: + return f"{self.owner}: [{SexChoicesWithAll(self.sex).label}]" class Rule(models.Model):