在 Manus 中运行任何 Skill
一键导入
一键导入
一键在 Manus 中运行任何 Skill
开始使用seeding
星标3
分支1
更新时间2026年2月16日 14:52
Best practices for seeding django models
安装
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
SKILL.md
readonly菜单
Best practices for seeding django models
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Service layer best practices on django models
How to implement badges in html templates.
How to implement Django Spire buttons in HTML templates.
How to implement container templates in Django Spire.
How to implement tab templates in Django Spire.
How to implement table templates in Django Spire.
| name | seeding |
| description | Best practices for seeding django models |
fields = {
'type': 'faker'
}
fk_random or fk_in_order methods when seedingfields: ClassVar = {
'product_id': ('custom', 'fk_in_order', {'model_class': Product}),
'inventory_id': ('custom', 'fk_random', {'model_class': Invenotry}),
}
custom date_time_between. This follow the same syntax as faker.Different data generation strategies serve different purposes:
("llm", "Describe this product for a sales catalog.")("faker", "word") or ("faker", "date_time_between", {"start_date": "-30d", "end_date": "now"})("static", True) or "in_stock": True("callable", lambda: timezone.now())("custom", "in_order", {"values": supplier_ids})class ProductSeeder(DjangoModelSeeder):
model_class = Product
default_to = "llm" # Options: 'llm', 'faker'
fields = {
'id': 'exclude',
'name': ('llm', 'A product in a clothing sales catalog'),
'description': ('llm', 'Describe this product for a clothing sales catalog.'),
'price': ('faker', 'pydecimal', {'left_digits': 2, 'right_digits': 2, 'positive': True}),
'in_stock': True,
'created_at': ('faker', 'date_time_between', {'start_date': '-30d', 'end_date': 'now'}),
'updated_at': lambda: timezone.now(),
'supplier_id': ('custom', 'in_order', {'values': supplier_ids})
}
Always configure caching for frequently-used seeders:
class ProductSeeder(DjangoModelSeeder):
cache_name = 'product_seeder'
cache_seed = True
default_to = "llm" or "faker" for automatic field populationLeverage built-in custom methods for common patterns:
in_order: Sequential value assignment for maintaining data relationshipsdate_time_between: Random date generation within rangesfk_random: Random foreign key selection from existing recordsfk_in_order: Sequential foreign key assignment for maintaining referential integrityseed() for object instantiation without DB insertionseed_database() for direct database insertionOverride fields to create specific test scenarios:
ProductSeeder.seed(
count=1,
fields={"in_stock": False}
)
Create specialized class methods that need to be re-used:
class ProductSeeder(DjangoModelSeeder):
@classmethod
def seed_grocery_product(cls, count: int = 1):
cls.seed_database(
count=count,
fields=cls.fields | {
'name': ('llm', 'Grocery product name'),
'description': ('llm', 'Grocery product description'),
}
)
# Product Seeder needs to link to batches and inventory
class ProductSeeder(DjangoModelSeeder):
...
@classmethod
def seed_with_inventory(cls, count: int = 1):
products = cls.seed_database(count=count)
for product in products:
BatchSeeder.seed_by_product(
product=product,
count=2,
)
return products
class BatchSeeder(DjangoModelSeeder):
...
@classmethod
def seed_by_product(
cls,
product: Product,
count: int = 1
):
batches = cls.seed_database(
count=count,
fields={
'product_id': product.id
}
)
for batch in batches:
InventorySeeder.seed_database(
count=3,
fields={
'product_id': product.id,
'batch_id': batch.id
}
)
return batches
class InventorySeeder(DjangoModelSeeder):
...
@classmethod
def seed_by_product_and_batch(cls, product, batch, count: int = 1):
"""
Seed inventory items specifically for a given product and batch.
This ensures proper relationship with both product and batch.
"""
return cls.seed_database(
count=count,
fields={
'product_id': product.id,
'batch_id': batch.id
}
)