What problem does it solve?
Django model creation can be complex, especially when adhering to specific architectural patterns like UUID primary keys, audit fields, and Pydantic validation for JSON fields. This Skill standardizes the process, preventing common errors and ensuring consistency across your codebase, allowing you to focus on business logic.
Core Features & Use Cases
- Pattern-Compliant Models: Automatically generate models inheriting from
BaseModel with UUID PKs and audit timestamps, ensuring architectural consistency.
- Pydantic JSON Validation: Implement robust, type-safe validation for JSON fields using Pydantic schemas, reducing data integrity issues.
- Relationship Management: Correctly define foreign keys, one-to-many, and many-to-many relationships with proper
on_delete behavior and related_name for efficient querying.
- Use Case: When starting a new feature that requires a new database table, use this Skill to quickly scaffold a model that perfectly fits your project's established patterns, complete with audit fields and complex JSON data validation, saving development and review time.
Quick Start
Define a Pydantic model for JSON field validation
from pydantic import BaseModel as PydanticBaseModel, Field
class CoverageDetailSchema(PydanticBaseModel):
coverage_type: str = Field(..., description="Type of coverage")
limit: float = Field(..., gt=0, description="Coverage limit")
Create the Django model inheriting from common.models.BaseModel
from django.db import models
from common.models import BaseModel # Assumes BaseModel exists
from pydantic import PydanticEncoder
class PolicyCoverage(BaseModel):
coverage_name: str = models.CharField(max_length=100)
coverage_details = models.JSONField(
default=dict,
encoder=PydanticEncoder,
help_text="Coverage details as validated JSON"
)