-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #952 from ae-utbm/sort-producttypes
Sort product types
- Loading branch information
Showing
28 changed files
with
731 additions
and
198 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
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
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
62 changes: 62 additions & 0 deletions
62
counter/migrations/0028_alter_producttype_comment_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,62 @@ | ||
# Generated by Django 4.2.17 on 2024-12-15 17:53 | ||
|
||
from django.db import migrations, models | ||
from django.db.migrations.state import StateApps | ||
|
||
|
||
def move_priority_to_order(apps: StateApps, schema_editor): | ||
"""Migrate the previous homemade `priority` to `OrderedModel.order`. | ||
`priority` was a system were click managers set themselves the priority | ||
of a ProductType. | ||
The higher the priority, the higher it was to be displayed in the eboutic. | ||
Multiple product types could share the same priority, in which | ||
case they were ordered by alphabetic order. | ||
The new field is unique per object, and works in the other way : | ||
the nearer from 0, the higher it should appear. | ||
""" | ||
ProductType = apps.get_model("counter", "ProductType") | ||
product_types = list(ProductType.objects.order_by("-priority", "name")) | ||
for order, product_type in enumerate(product_types): | ||
product_type.order = order | ||
ProductType.objects.bulk_update(product_types, ["order"]) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [("counter", "0027_alter_refilling_payment_method")] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="producttype", | ||
name="comment", | ||
field=models.TextField( | ||
default="", | ||
help_text="A text that will be shown on the eboutic.", | ||
verbose_name="comment", | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="producttype", | ||
name="description", | ||
field=models.TextField(default="", verbose_name="description"), | ||
), | ||
migrations.AlterModelOptions( | ||
name="producttype", | ||
options={"ordering": ["order"], "verbose_name": "product type"}, | ||
), | ||
migrations.AddField( | ||
model_name="producttype", | ||
name="order", | ||
field=models.PositiveIntegerField( | ||
db_index=True, default=0, editable=False, verbose_name="order" | ||
), | ||
preserve_default=False, | ||
), | ||
migrations.RunPython( | ||
move_priority_to_order, | ||
reverse_code=migrations.RunPython.noop, | ||
elidable=True, | ||
), | ||
migrations.RemoveField(model_name="producttype", name="priority"), | ||
] |
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.