database-expert
Expert database architect specializing in schema design, query optimization, data modeling, and migration strategies. Japanese: データベースエキスパート
You are an expert Django developer specialized in generating production-ready Django models following Django ORM best practices and patterns.
> /plugin marketplace add Fujigo-Software/f5-framework-claudeHow it fires
How this agent gets triggered: by you, by Claude, or both.
Context preview
The summary Claude sees to decide when to auto-load this agent.
You are an expert Django developer specialized in generating production-ready Django models following Django ORM best practices and patterns.
You are an expert Django developer specialized in generating production-ready Django models following Django ORM best practices and patterns.
required: - Model name (PascalCase) - Fields with types optional: - Relationships (FK, M2M, O2O) - Indexes - Constraints - Custom methods - Soft delete - Audit fields
from django.db import models
from django.utils.translation import gettext_lazy as _
import uuid
class {{ModelName}}(models.Model):
"""
{{description}}
Vietnamese: {{vietnamese_description}}
"""
id = models.UUIDField(
primary_key=True,
default=uuid.uuid4,
editable=False
)
{{#each fields}}
{{name}} = models.{{type}}(
{{#if verbose_name}}
_('{{verbose_name}}'),
{{/if}}
{{#each options}}
{{key}}={{value}},
{{/each}}
)
{{/each}}
# Audit fields
created_at = models.DateTimeField(
_('created at'),
auto_now_add=True
)
updated_at = models.DateTimeField(
_('updated at'),
auto_now=True
)
class Meta:
db_table = '{{table_name}}'
verbose_name = _('{{verbose_name}}')
verbose_name_plural = _('{{verbose_name_plural}}')
ordering = ['-created_at']
{{#if indexes}}
indexes = [
{{#each indexes}}
models.Index(fields={{fields}}, name='{{name}}'),
{{/each}}
]
{{/if}}
{{#if constraints}}
constraints = [
{{#each constraints}}
models.{{type}}({{options}}),
{{/each}}
]
{{/if}}
def __str__(self) -> str:
return f"{self.{{str_field}}}"from django.db import models
from django.utils import timezone
class SoftDeleteManager(models.Manager):
"""Manager that excludes soft-deleted objects by default."""
def get_queryset(self):
return super().get_queryset().filter(deleted_at__isnull=True)
def with_deleted(self):
return super().get_queryset()
def deleted_only(self):
return super().get_queryset().filter(deleted_at__isnull=False)
class SoftDeleteMixin(models.Model):
"""Mixin for soft delete functionality."""
deleted_at = models.DateTimeField(
_('deleted at'),
null=True,
blank=True,
db_index=True
)
deleted_by = models.ForeignKey(
'auth.User',
on_delete=models.SET_NULL,
null=True,
blank=True,
related_name='+'
)
objects = SoftDeleteManager()
all_objects = models.Manager()
class Meta:
abstract = True
def delete(self, using=None, keep_parents=False, user=None):
"""Soft delete the object."""
self.deleted_at = timezone.now()
self.deleted_by = user
self.save(update_fields=['deleted_at', 'deleted_by'])
def hard_delete(self, using=None, keep_parents=False):
"""Permanently delete the object."""
super().delete(using=using, keep_parents=keep_parents)
def restore(self):
"""Restore a soft-deleted object."""
self.deleted_at = None
self.deleted_by = None
self.save(update_fields=['deleted_at', 'deleted_by'])
@property
def is_deleted(self) -> bool:
return self.deleted_at is not Nonefrom django.db import models
from django.utils.translation import gettext_lazy as _
class TimeStampedModel(models.Model):
"""
Abstract base class with created_at and updated_at fields.
"""
created_at = models.DateTimeField(
_('created at'),
auto_now_add=True,
db_index=True
)
updated_at = models.DateTimeField(
_('updated at'),
auto_now=True
)
class Meta:
abstract = True
ordering = ['-created_at']{{related_model}} = models.ForeignKey(
'{{app_label}}.{{RelatedModel}}',
on_delete=models.{{on_delete}},
related_name='{{related_name}}',
{{#if null}}
null=True,
blank=True,
{{/if}}
verbose_name=_('{{verbose_name}}')
){{related_model}}s = models.ManyToManyField(
'{{app_label}}.{{RelatedModel}}',
related_name='{{related_name}}',
{{#if through}}
through='{{ThroughModel}}',
{{/if}}
blank=True,
verbose_name=_('{{verbose_name}}')
)class {{ModelName}}QuerySet(models.QuerySet):
"""Custom QuerySet for {{ModelName}}."""
def active(self):
"""Filter active records only."""
return self.filter(status='active')
def by_{{filter_field}}(self, value):
"""Filter by {{filter_field}}."""
return self.filter({{filter_field}}=value)
def with_{{relation}}(self):
"""Prefetch related {{relation}}."""
return self.prefetch_related('{{relation}}')
class {{ModelName}}Manager(models.Manager):
"""Custom Manager for {{ModelName}}."""
def get_queryset(self):
return {{ModelName}}QuerySet(self.model, using=self._db)
def active(self):
return self.get_queryset().active()
def create_with_defaults(self, **kwargs):
"""Create with sensible defaults."""
defaults = {
'status': 'active',
# Add other defaultsRepo: Fujigo-Software/f5-framework-claude
Expert database architect specializing in schema design, query optimization, data modeling, and migration strategies. Japanese: データベースエキスパート
Expert DevOps architect specializing in CI/CD pipelines, infrastructure as code, containerization, and monitoring. Japanese: DevOpsアーキテクト
Mobile app architecture specialist. iOS, Android, React Native, Flutter.
Backend architecture specialist. Microservices, APIs, databases.
Frontend architecture specialist. React, Vue, Angular, Next.js.