Cdrf Expert

作者 vintasoftwareb8af2688d994无许可证152 个星标收录于 2026年10月8日更新于 2026年10月8日仓库2个月前更新

Expert guidance for Django REST Framework class-based views using Classy DRF (https://www.cdrf.co). Use when selecting or debugging APIView, GenericAPIView, concrete generic views, mixin combinations, or ViewSet/GenericViewSet/ModelViewSet behavior; tracing method resolution order (MRO); understanding which method to override (`create` vs `perform_create`, `update` vs `perform_update`, `destroy` vs `perform_destroy`, `get_queryset`, `get_serializer_class`); and comparing behavior across DRF versions. Do not use for function-based views, GraphQL, FastAPI/Flask, frontend work, or non-DRF backend frameworks.

AI 生成的概览

借助 Classy DRF 参考资料,指导 Django REST Framework 基于类的视图选择、重写点、MRO 追踪与版本差异。

功能
该技能把 Django REST Framework 基于类的视图问题归类为类选择、生命周期追踪、重写策略、MRO 调试或版本差异等类别,然后只加载对应的参考文件。它引导代理查阅特定版本的 Classy DRF 页面,以获取祖先类、方法来源和默认属性。最终产出推荐的类、应重写的方法、基于方法解析顺序与生命周期的理由、简短的代码补丁或骨架,以及风险和应补充的测试。
适用场景
适用于在 APIView、GenericAPIView、具体通用视图、mixin 或 ViewSet 之间做选择,或判断应重写 create 还是 perform_create 等钩子时。也适合追踪某个方法来自哪个类,以及比较不同 DRF 版本之间的行为差异。不适用于函数式视图、GraphQL、FastAPI 或 Flask、前端工作,或非 DRF 后端框架。
运行要求
需要访问 cdrf.co 的网络连接,并在不可用时回退到 DRF 官方文档和已安装的源代码。用户应提供项目的 DRF 版本,或接受明确标注的版本无关假设。该技能不包含脚本,只有参考文档。

CDRF Expert

Instructions

  1. Classify the request.

Map the user request to one or more categories:

  • Class selection (APIView vs GenericAPIView vs concrete generics vs ViewSets)
  • Lifecycle tracing (request-to-response flow)
  • Override strategy (which hook to customize)
  • MRO debugging (method came from mixin/base class)
  • Version differences (behavior changed between DRF versions)
  1. Read only the required reference file(s).

Load the minimum needed context:

  • references/class-selection-matrix.md for class selection
  • references/lifecycle-and-overrides.md for hook placement and lifecycle
  • references/mro-debugging-playbook.md for MRO/source-of-method tracing
  • references/version-check-workflow.md for DRF-version comparisons
  1. Navigate cdrf.co with version-first discipline.
  • Identify the project DRF version from user context.
  • If unknown, ask for version or provide a version-agnostic answer and explicitly mark assumptions.
  • Open the matching CDRF version namespace first (for example https://www.cdrf.co/3.16/).
  • Open the target class page and extract:
    • Ancestors and MRO
    • Available methods and source class for each method
    • Default attributes that affect behavior (queryset, serializer_class, pagination/filter backends)
  1. Choose the minimal override point.
  • Prefer narrow hooks (perform_create, perform_update, perform_destroy) before broad methods (create, update, destroy).
  • Prefer get_queryset and get_serializer_class for per-request behavior over hardcoding class attributes.
  • Keep HTTP orchestration in view methods and business/domain logic outside views.
  • Preserve DRF defaults unless the request needs behavior changes.
  1. Produce an answer grounded in method flow.

Return:

  • Recommended class
  • Method(s) to override
  • Why these methods are correct in the MRO/lifecycle
  • Concise code patch or skeleton
  • Risks/regressions and tests to add
  1. Validate before finalizing.

Check for common regressions:

  • Accidentally bypassing permission/authentication/filter/pagination hooks
  • Duplicating object-save logic between serializer and view
  • Overriding broad methods when narrow hooks are sufficient
  • Depending on methods not present in the selected DRF version

Error Handling

  1. If cdrf.co is unavailable, state that limitation and fall back to DRF official docs and installed source code.
  2. If the user cannot provide DRF version, provide a version-agnostic path and clearly mark assumptions.
  3. If multiple override points appear valid, recommend the narrowest hook first and explain tradeoffs.

Output Rules

  • Cite exact class and method names from CDRF.
  • State assumptions when DRF version is unknown.
  • Keep responses focused on DRF CBV internals and actionable code changes.

来源与署名

来源:vintasoftware/django-ai-plugins位于skills/cdrf-expert提交b8af268

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架