-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
apps/kiezradar: add automatic naming to SearchProfile based on an inc…
…reasing number per user
- Loading branch information
Showing
8 changed files
with
223 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
### Added | ||
|
||
- add a new field `number` to SearchProfile which indexes the search profiles per | ||
user | ||
- add auto-naming to SearchProfiles for unnamed search profiles | ||
|
||
### Changed | ||
|
||
- make `name` field on SearchProfile optional as users can only change it after | ||
creation and it makes accommodating the auto-naming scheme easier |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
meinberlin/apps/kiezradar/migrations/0006_searchprofile_number.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Generated by Django 4.2.11 on 2025-01-09 15:25 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("meinberlin_kiezradar", "0005_populate_project_status"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="searchprofile", | ||
name="number", | ||
field=models.PositiveSmallIntegerField(null=True), | ||
), | ||
migrations.AddIndex( | ||
model_name="searchprofile", | ||
index=models.Index(models.F("number"), name="searchprofile_number_idx"), | ||
), | ||
migrations.AlterModelOptions( | ||
name="searchprofile", | ||
options={"ordering": ["number"]}, | ||
), | ||
migrations.AlterField( | ||
model_name="searchprofile", | ||
name="name", | ||
field=models.CharField(max_length=255, null=True), | ||
), | ||
] |
41 changes: 41 additions & 0 deletions
41
meinberlin/apps/kiezradar/migrations/0007_alter_searchprofile_number_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Generated by Django 4.2.11 on 2025-01-09 15:26 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
def add_number_to_search_profiles(apps, schema_editor): | ||
SearchProfile = apps.get_model("meinberlin_kiezradar", "SearchProfile") | ||
for sp in SearchProfile.objects.all(): | ||
if sp.number is None: | ||
latest = None | ||
try: | ||
latest = ( | ||
SearchProfile.objects.filter(number__isnull=False) | ||
.filter(user=sp.user) | ||
.latest("number") | ||
) | ||
except SearchProfile.DoesNotExist: | ||
pass | ||
sp.number = latest.number + 1 if latest else 1 | ||
sp.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("meinberlin_kiezradar", "0006_searchprofile_number"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(add_number_to_search_profiles, migrations.RunPython.noop), | ||
migrations.AlterField( | ||
model_name="searchprofile", | ||
name="number", | ||
field=models.PositiveSmallIntegerField(), | ||
), | ||
migrations.AddConstraint( | ||
model_name="searchprofile", | ||
constraint=models.UniqueConstraint( | ||
models.F("user"), models.F("number"), name="unique-search-profile" | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters