feat: Allow location to be null in SearchSubscription
This commit is contained in:
		@@ -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),
 | 
				
			||||||
 | 
					        ),
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
@@ -559,12 +559,15 @@ class SearchSubscription(models.Model):
 | 
				
			|||||||
    - For matches: Send notification to user of the SearchSubscription
 | 
					    - For matches: Send notification to user of the SearchSubscription
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    owner = models.ForeignKey(User, on_delete=models.CASCADE)
 | 
					    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)
 | 
					    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):
 | 
					    def __str__(self):
 | 
				
			||||||
 | 
					        if self.location and self.max_distance:
 | 
				
			||||||
            return f"{self.owner}: [{SexChoicesWithAll(self.sex).label}] {self.max_distance}km - {self.location}"
 | 
					            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):
 | 
					class Rule(models.Model):
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user