bartczak-pa / Cookbook

0 stars 0 forks source link

[Refactor] Change RecipeDetailView to display recipe slug instead of id #14

Closed bartczak-pa closed 2 months ago

bartczak-pa commented 2 months ago

Summary

Refactor the RecipeDetailView to use slugs instead of IDs for displaying recipe details, enhancing URL readability and SEO. Update the Recipe model to include a slug field and adjust URL patterns and templates accordingly. Add tests to verify the new slug-based functionality.

New Features:

Enhancements:

Tests:

sourcery-ai[bot] commented 2 months ago

Reviewer's Guide by Sourcery

This pull request refactors the RecipeDetailView to use slugs instead of IDs for displaying recipe details. It enhances URL readability and SEO by introducing a slug field to the Recipe model and adjusting URL patterns and templates accordingly. The changes include updating the Recipe and Category models, modifying views, templates, and URLs, and adding new tests to verify the slug-based functionality.

File-Level Changes

Change Details Files
Introduce slug field to Recipe model and update Category model
  • Add AutoSlugField to Recipe model, populated from the title
  • Change Category model's slug field to AutoSlugField, populated from the name
  • Remove custom save method from Category model as it's no longer needed
  • Add migrations for the new slug fields
recipes/models.py
recipes/migrations/0002_recipe_slug.py
recipes/migrations/0003_alter_recipe_slug.py
recipes/migrations/0004_alter_category_slug.py
Refactor RecipeDetailView to use slugs
  • Update get_queryset method to filter by category slug
  • Add select_related and prefetch_related calls for better performance
  • Modify get_context_data method to use type hints
recipes/views.py
Update URL patterns to use slugs
  • Change recipe detail URL pattern to use category_slug and recipe slug instead of pk
recipes/urls.py
Update templates to use new URL structure
  • Modify recipe detail links in category_recipes_list.html and recipe_list.html to use new URL structure with slugs
recipes/templates/recipes/category_recipes_list.html
recipes/templates/recipes/recipe_list.html
Add new tests for RecipeDetailView
  • Create TestRecipeDetailView class with setup fixture
  • Add tests for get_object method with various scenarios
  • Add tests for get_queryset and get_context_data methods
recipes/tests/test_views.py

Tips - Trigger a new Sourcery review by commenting `@sourcery-ai review` on the pull request. - Continue your discussion with Sourcery by replying directly to review comments. - You can change your review settings at any time by accessing your [dashboard](https://app.sourcery.ai): - Enable or disable the Sourcery-generated pull request summary or reviewer's guide; - Change the review language; - You can always [contact us](mailto:support@sourcery.ai) if you have any questions or feedback.
bartczak-pa commented 2 months ago

@sourcery-ai review

bartczak-pa commented 2 months ago

@sourcery-ai review