-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Labels: Added complex filtering logic
- Loading branch information
1 parent
acd8337
commit a425f26
Showing
13 changed files
with
293 additions
and
180 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,28 @@ | ||
# Generated by Django 3.2.18 on 2023-12-19 16:15 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('seed', '0210_natural_sort'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='filtergroup', | ||
name='and_labels', | ||
field=models.ManyToManyField(related_name='and_filter_groups', to='seed.StatusLabel'), | ||
), | ||
migrations.AddField( | ||
model_name='filtergroup', | ||
name='exclude_labels', | ||
field=models.ManyToManyField(related_name='exclude_filter_groups', to='seed.StatusLabel'), | ||
), | ||
migrations.AddField( | ||
model_name='filtergroup', | ||
name='or_labels', | ||
field=models.ManyToManyField(related_name='or_filter_groups', to='seed.StatusLabel'), | ||
), | ||
] |
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,40 @@ | ||
# Generated by Django 3.2.18 on 2023-12-19 16:15 | ||
|
||
from django.db import migrations | ||
|
||
def move_filter_groups(apps, schema_editor): | ||
FilterGroup = apps.get_model('seed', 'FilterGroup') | ||
for filter_group in FilterGroup.objects.all(): | ||
if filter_group.labels.exists() and filter_group.label_logic == 0: # and | ||
filter_group.and_labels.set(filter_group.labels.all()) | ||
elif filter_group.labels.exists() and filter_group.label_logic == 1: # or | ||
filter_group.or_labels.set(filter_group.labels.all()) | ||
elif filter_group.labels.exists() and filter_group.label_logic == 2: # exclude | ||
filter_group.exclude_labels.set(filter_group.labels.all()) | ||
|
||
def move_filter_groups_back(apps, schema_editor): | ||
# if the filter group only has one set of labels, we can move those back | ||
FilterGroup = apps.get_model('seed', 'FilterGroup') | ||
for filter_group in FilterGroup.objects.all(): | ||
if filter_group.and_labels.exists() and not (filter_group.or_labels.exists() or filter_group.exclude_labels.exists()): | ||
filter_group.labels.set(filter_group.and_labels.all()) | ||
filter_group.label_logic = 0 | ||
filter_group.save() | ||
elif filter_group.or_labels.exists() and not (filter_group.and_labels.exists() or filter_group.exclude_labels.exists()): | ||
filter_group.labels.set(filter_group.or_labels.all()) | ||
filter_group.label_logic = 1 | ||
filter_group.save() | ||
elif filter_group.exclude_labels.exists() and not (filter_group.and_labels.exists() or filter_group.or_labels.exists()): | ||
filter_group.labels.set(filter_group.exclude_labels.all()) | ||
filter_group.label_logic = 2 | ||
filter_group.save() | ||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('seed', '0211_add_filtergroup_labels'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(move_filter_groups, move_filter_groups_back) | ||
] |
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,21 @@ | ||
# Generated by Django 3.2.18 on 2023-12-19 16:20 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('seed', '0212_move_filtergroup_labels'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='filtergroup', | ||
name='label_logic', | ||
), | ||
migrations.RemoveField( | ||
model_name='filtergroup', | ||
name='labels', | ||
), | ||
] |
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
Oops, something went wrong.