BO 1.18 clone training_plan_id sort = max(sort) + 1

This commit is contained in:
Bossanyi Tibor 2021-05-23 19:42:39 +02:00
parent 1812fc4d52
commit b5425a74d8
2 changed files with 15 additions and 7 deletions

View File

@ -12,9 +12,9 @@ class TranslationTrainingPlanInline(admin.TabularInline):
class TrainingPlanAdmin(admin.ModelAdmin): class TrainingPlanAdmin(admin.ModelAdmin):
list_display = ('training_plan_id', 'name','internal_name', 'free') list_display = ('training_plan_id', 'name', 'internal_name', 'free')
fields = ('tree', 'name','description', 'internal_name', 'free') fields = ('tree', 'name', 'description', 'internal_name', 'free')
list_editable = ('name','internal_name', 'free') list_editable = ('name', 'internal_name', 'free')
inlines = [ inlines = [
TranslationTrainingPlanInline TranslationTrainingPlanInline
@ -53,22 +53,31 @@ class TrainingPlanDetailAdmin(admin.ModelAdmin):
return response return response
def copy_attributes(self, request, queryset): def copy_attributes(self, request, queryset):
name = str(queryset[0].training_plan)
details = TrainingPlanDetail.objects.filter(training_plan__name=name).order_by('sort')
new_sort = details[len(details)-1].sort + 1
for objectAttr in reversed(queryset): for objectAttr in reversed(queryset):
objectAttr.pk = None objectAttr.pk = None
objectAttr.sort = objectAttr.sort + 1 objectAttr.sort = new_sort
objectAttr.save() objectAttr.save()
new_sort = new_sort + 1
copy_attributes.short_description = _("Clone the selected Training Plan Detail") copy_attributes.short_description = _("Clone the selected Training Plan Detail")
def select_max_repeat(self, request, queryset): def select_max_repeat(self, request, queryset):
for obj in queryset: for obj in queryset:
obj.repeats = -1 obj.repeats = -1
obj.save() obj.save()
select_max_repeat.short_description = _("Select the exercises with MAX repeats") select_max_repeat.short_description = _("Select the exercises with MAX repeats")
def select_weight_calc(self, request, queryset): def select_weight_calc(self, request, queryset):
for obj in queryset: for obj in queryset:
obj.weight = -1 obj.weight = -1
obj.save() obj.save()
select_weight_calc.short_description = _("Select the exercises CALCULATED weight") select_weight_calc.short_description = _("Select the exercises CALCULATED weight")
def max(self, obj): def max(self, obj):

View File

@ -139,4 +139,3 @@ volumes:
media: media:
wordpress: wordpress:
mautic_data: mautic_data:
xwiki-data: