-
Notifications
You must be signed in to change notification settings - Fork 588
Feature/reorder ingredients countries 565 #571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Feature/reorder ingredients countries 565 #571
Conversation
…untry and BreadIngredient (wagtail#565) - Add sort_order field to Country model with db_index - Add Orderable mixin to BreadIngredient model - Update model Meta ordering to prioritize sort_order - Add sort_order_field to CountryModelViewSet and BreadIngredientSnippetViewSet - Enable drag-and-drop reordering in Wagtail admin (7.2+) - Maintain backward compatibility with Wagtail 7.1
…ail#565) - Backfill sort_order for existing Country and BreadIngredient instances - Assign values based on alphabetical order (name/title) - Use increments of 10 for flexibility in future reordering - Include reverse migration to restore None values
…templates (wagtail#564 wagtail#565) - Add deterministic sort_order values to Country and BreadIngredient fixtures - Sort fixtures alphabetically to ensure predictable display order - Update bread_page.html template to order ingredients by sort_order - Fixes missing ingredient data display issue (wagtail#564)
…error (wagtail#565) - Add ordered_ingredients property to BreadPage model - Return ingredients ordered by sort_order, then name - Update template to use property instead of method call - Fixes TemplateSyntaxError from .order_by() in template
1f4f482 to
067a4f2
Compare
|
Fixed template syntax error by adding ordered_ingredients property to BreadPage model. Django templates cannot call methods with arguments like .order_by(), so I created a property that returns the ordered queryset. |
|
Thank you for giving this a go @Mohit-Lakra. Note #564 and #565 were already assigned to someone else. In the future, if you see an issue has an assignee, it’s worth checking with them in the issue comments so multiple people aren’t needlessly working on the same task. I see you’ve used ChatGPT for this, could you share more information about how you used it? Screenshots / copies of the prompts, or use the "Share" feature if you can so I can see the sequence? There are a lot of changes in here, I’d like to check its reasoning for some of them, and whether ChatGPT tested with Wagtail 7.2 or no. |
|
Hi @thibaudcolas , sorry about that — I missed that the issue was already assigned to someone else. I’ll make sure to check for assignees and confirm in the comments before picking up any future issues. |
Add reordering for Countries and Ingredients; fix ingredients data
Summary
This PR implements reordering support for
CountryandBreadIngredientmodels, enabling drag-and-drop reordering in the Wagtail admin interface (Wagtail 7.2+). It also fixes the broken ingredients data issue (#564).Closes #565. Fixes #564.
Changes
Models (Country & BreadIngredient)
sort_orderfield to both modelsCountry: explicitIntegerFieldwithdb_index=TrueBreadIngredient: usesOrderablemixin from WagtailMeta.orderingto prioritizesort_order, then fall back totitle/nameAdmin Interface
sort_order_field = "sort_order"toCountryModelViewSetandBreadIngredientSnippetViewSetsort_orderfirstData Migrations
sort_orderfields and update orderingsort_orderfor existing recordsDemo Data
sort_ordervalues for all Countries and IngredientsTemplates
bread_page.htmlto respectsort_orderwhen displaying ingredients.all()to.order_by('sort_order', 'name')Tests
sort_orderfield existence and behaviorsort_ordervaluesBehavior
Wagtail 7.1 (Current)
sort_orderfields and respect orderingWagtail 7.2+ (Future)
sort_orderQA Checklist
sort_ordervaluessort_orderin Metasort_order_fieldTesting Instructions
Fresh Install
Upgrade from Existing Database
Manual Admin Testing (Wagtail 7.2+)
Implementation Notes
Why Orderable for BreadIngredient but not Country?
BreadIngredientalready usesDraftStateMixinandRevisionMixin, so addingOrderableis consistent with the patternCountryis a simpler model without draft/revision support, so a plainIntegerFieldis more appropriateWhy Increments of 10?
Using increments of 10 (10, 20, 30...) instead of 1, 2, 3 provides flexibility:
Fixture Update Strategy
The fixture was updated using a Python script that:
sort_ordervalues in increments of 10Commits
feat(breads): add sort_order field and enable admin reordering- Core functionalitychore(breads): add data migration to backfill sort_order values- Data migrationfix(breads): populate sort_order in fixtures and respect ordering in templates- Demo data and UItest(breads): add ordering and sort_order field tests- Test coverageRelated Issues