Docs: начальная структура проекта
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
12
app/documents/services.py
Normal file
12
app/documents/services.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from django.db.models import Max
|
||||
|
||||
def next_number(model_class, field_name="number"):
|
||||
"""Следующий номер по порядку (максимум + 1). Для числоподобных строк."""
|
||||
agg = model_class.objects.aggregate(m=Max(field_name))
|
||||
current = agg["m"]
|
||||
if current is None:
|
||||
return "1"
|
||||
try:
|
||||
return str(int(current) + 1)
|
||||
except (ValueError, TypeError):
|
||||
return "1"
|
||||
Reference in New Issue
Block a user