New Features - Adopt double-bracket placeholders (`[[ var ]]`) and rename templates to `.py-tpl`/.`md-tpl` extensions. - Introduce new `runtime_txt-tpl` template. Enhancements - Update `api_readme`, `models`, `apps`, `routes`, `pyproject`, `readme`, and `requirements` templates with new syntax and naming. - Align placeholder naming with a unified convention. Bug Fixes - None.
37 lines
1.1 KiB
Plaintext
37 lines
1.1 KiB
Plaintext
from [[ app_module ]].models.[[ app_name ]] import [[ model_class_name ]]
|
|
|
|
|
|
class [[ model_class_name ]]Service:
|
|
"""Service class for [[ model_class_name ]] business logic."""
|
|
|
|
@staticmethod
|
|
def get_all():
|
|
"""Get all [[ model_class_name ]] instances."""
|
|
return [[ model_class_name ]].objects.all()
|
|
|
|
@staticmethod
|
|
def get_by_id(id):
|
|
"""Get [[ model_class_name ]] by ID."""
|
|
try:
|
|
return [[ model_class_name ]].objects.get(id=id)
|
|
except [[ model_class_name ]].DoesNotExist:
|
|
return None
|
|
|
|
@staticmethod
|
|
def create(data):
|
|
"""Create a new [[ model_class_name ]] instance."""
|
|
return [[ model_class_name ]].objects.create(**data)
|
|
|
|
@staticmethod
|
|
def update(instance, data):
|
|
"""Update an existing [[ model_class_name ]] instance."""
|
|
for key, value in data.items():
|
|
setattr(instance, key, value)
|
|
instance.save()
|
|
return instance
|
|
|
|
@staticmethod
|
|
def delete(instance):
|
|
"""Delete a [[ model_class_name ]] instance."""
|
|
instance.delete()
|