django_spire/core/management/commands/spire_opencode_pkg/skills/models/SKILL.md
Best practice for working with Django models
npx skillsauth add stratusadv/django-spire django-modelsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Use the following guidelines when working in models.py files.
class InventoryBatch(HistoryModelMixin, ActivityMixin):
product = models.ForeignKey(
'product.Product',
on_delete=models.CASCADE,
related_name='batches',
related_query_name='batch'
)
location = models.ForeignKey(
'inventory_location.InventoryLocation', # note here how the patter is app_name.ModelName.
on_delete=models.CASCADE,
related_name='inventory',
related_query_name='inventory',
null=True,
blank=True
)
name = models.CharField(max_length=255)
unit_of_measure = models.CharField(
max_length=3,
choices=ProductUnitOfMeasureChoices.choices,
default=ProductUnitOfMeasureChoices.LB
)
'app_name.ModelName'.
related_name It should read like English with the related model. Typically, it is the plural version but doesn't have to be.
related_query_name is the singular version of the word.
class InventoryBatch(HistoryModelMixin, ActivityMixin):
product = models.ForeignKey(
'product.Product',
on_delete=models.CASCADE,
related_name='batches',
related_query_name='batch'
)
location = models.ForeignKey(
'inventory_location.InventoryLocation', # note here how the patter is app_name.ModelName.
on_delete=models.CASCADE,
related_name='inventory',
related_query_name='inventory',
null=True,
blank=True
)
# app/product/choices.py
from django.db.models import TextChoices
class ProductTypeChoices(TextChoices):
RAW = 'raw', 'Raw'
WORK_IN_PROGRESS = 'wip', 'Work in Progress'
FINISHED_GOOD = 'fin', 'Finished Good'
# app/product/models.py
from django.db import models
from app.product import choices
class Product(models.Model):
unit_of_measure = models.CharField(
max_length=3,
choices=choices.ProductUnitOfMeasureChoices.choices,
default=choices.ProductUnitOfMeasureChoices.LB
)
development
How to implement table templates in Django Spire.
development
How to implement tab templates in Django Spire.
development
Service layer best practices on django models
development
Best practices for seeding django models