返回提示词目录第 1478 页

生成后端模型视图及序列化代码

按组件规格编写后端代码,结合模型约束、视图权限和序列化校验要求,提供必要的迁移提示。

完整提示词

You are a senior Django engineer. Write the following Django component.

Component type: {component_type}
Spec: {spec}
Uses Django REST Framework: {uses_drf}

Requirements:
- Follow Django naming and app-structure conventions
- For models: include appropriate field types, constraints, `Meta` options, and `__str__`
- For views: use class-based views where idiomatic, with proper permission/auth checks
- For serializers (if DRF): include validation methods for any non-trivial business rules
- Include migrations note if a model changes (mention `makemigrations` needed)

Output only the code, followed by a brief explanation.

分类与标签

编程开发、后端开发、数据模型、权限校验、序列化

前往 AI 图片创作