BO 1.26 ExerciseType list extensions, TrainingPlan Details inline
This commit is contained in:
parent
c2ce0261a9
commit
b8b347c102
@ -47,7 +47,7 @@ class ExerciseTypeParentsInline(admin.TabularInline):
|
|||||||
|
|
||||||
|
|
||||||
class ExerciseTypeAdmin(admin.ModelAdmin):
|
class ExerciseTypeAdmin(admin.ModelAdmin):
|
||||||
list_display = ('exercise_type_id', 'name_colored', 'active', 'base', 'buddy_warning')
|
list_display = ('exercise_type_id', 'name_colored', 'active', 'base', 'buddy_warning', 'is_description', 'is_desc_hu', 'alternatives')
|
||||||
search_fields = ['name', 'exercisetypetranslation__name']
|
search_fields = ['name', 'exercisetypetranslation__name']
|
||||||
fields = ('name', 'description', 'unit', 'unit_quantity', 'unit_quantity_unit', 'active', 'base', 'buddy_warning')
|
fields = ('name', 'description', 'unit', 'unit_quantity', 'unit_quantity_unit', 'active', 'base', 'buddy_warning')
|
||||||
|
|
||||||
@ -65,6 +65,31 @@ class ExerciseTypeAdmin(admin.ModelAdmin):
|
|||||||
name_colored.admin_order_field = 'name'
|
name_colored.admin_order_field = 'name'
|
||||||
name_colored.short_description = 'name'
|
name_colored.short_description = 'name'
|
||||||
|
|
||||||
|
def is_description(self, obj):
|
||||||
|
if not obj.description:
|
||||||
|
return "-"
|
||||||
|
else:
|
||||||
|
return "OK"
|
||||||
|
|
||||||
|
is_description.short_description = 'desc'
|
||||||
|
|
||||||
|
def is_desc_hu(self, obj):
|
||||||
|
desc_hu = ",".join([k.description for k in obj.exercisetypetranslation_set.all()])
|
||||||
|
if not desc_hu:
|
||||||
|
return "-"
|
||||||
|
else:
|
||||||
|
return "OK"
|
||||||
|
|
||||||
|
is_desc_hu.short_description = 'desc HU'
|
||||||
|
|
||||||
|
def alternatives(self, obj):
|
||||||
|
alternatives = []
|
||||||
|
for k in obj.exercise_type_child.all():
|
||||||
|
alternatives.append(k.exercise_type_parent_id)
|
||||||
|
return ", " . join([ExerciseType.objects.get(pk=id).name for id in alternatives])
|
||||||
|
|
||||||
|
alternatives.short_description = 'alternatives'
|
||||||
|
|
||||||
inlines = [
|
inlines = [
|
||||||
ImageInline,
|
ImageInline,
|
||||||
TranslationInline,
|
TranslationInline,
|
||||||
|
@ -5,6 +5,85 @@ from django.utils.translation import ugettext_lazy as _
|
|||||||
from ..models.training_plan import TrainingPlan, TrainingPlanDetail, TrainingPlanTranslation
|
from ..models.training_plan import TrainingPlan, TrainingPlanDetail, TrainingPlanTranslation
|
||||||
|
|
||||||
|
|
||||||
|
class TrainingPlanDetailInline(admin.TabularInline):
|
||||||
|
model = TrainingPlanDetail
|
||||||
|
#fk_name = 'training_plan_detail_id'
|
||||||
|
list_display = (
|
||||||
|
'training_plan', 'exercise_type', 'sort', 'set', 'repeats', 'max', 'weight', 'calc',
|
||||||
|
'resting_time', 'parallel', 'day')
|
||||||
|
list_filter = ('training_plan__name', 'exercise_type__name')
|
||||||
|
list_editable = (
|
||||||
|
'exercise_type', 'sort', 'set', 'repeats', 'weight', 'resting_time', 'parallel', 'day')
|
||||||
|
ordering = ('sort',)
|
||||||
|
|
||||||
|
def repeat_max(self, obj):
|
||||||
|
if obj.repeat_max:
|
||||||
|
obj.repeats = -1
|
||||||
|
else:
|
||||||
|
obj.repeats = 0
|
||||||
|
|
||||||
|
def get_training_plan_info_info(self):
|
||||||
|
first_row = _("Special cases: Weight = -1 IF the Weight should be calculated.")
|
||||||
|
second_row = _("Repeats = -1 IF the repeats should be maximized")
|
||||||
|
return first_row + second_row
|
||||||
|
|
||||||
|
def changelist_view(self, request, extra_context=None):
|
||||||
|
response = super(TrainingPlanDetailAdmin, self).changelist_view(request, extra_context)
|
||||||
|
extra_context = {
|
||||||
|
'extra_hint': self.get_training_plan_info_info()
|
||||||
|
}
|
||||||
|
try:
|
||||||
|
response.context_data.update(extra_context)
|
||||||
|
except Exception as e:
|
||||||
|
pass
|
||||||
|
return response
|
||||||
|
|
||||||
|
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 queryset:
|
||||||
|
objectAttr.pk = None
|
||||||
|
objectAttr.sort = new_sort
|
||||||
|
objectAttr.save()
|
||||||
|
new_sort = new_sort + 1
|
||||||
|
|
||||||
|
copy_attributes.short_description = _("Clone the selected Training Plan Detail")
|
||||||
|
|
||||||
|
def select_max_repeat(self, request, queryset):
|
||||||
|
for obj in queryset:
|
||||||
|
obj.repeats = -1
|
||||||
|
obj.save()
|
||||||
|
|
||||||
|
select_max_repeat.short_description = _("Select the exercises with MAX repeats")
|
||||||
|
|
||||||
|
def select_weight_calc(self, request, queryset):
|
||||||
|
for obj in queryset:
|
||||||
|
obj.weight = -1
|
||||||
|
obj.save()
|
||||||
|
|
||||||
|
select_weight_calc.short_description = _("Select the exercises CALCULATED weight")
|
||||||
|
|
||||||
|
def max(self, obj):
|
||||||
|
color_code = "000000"
|
||||||
|
if obj.repeats and obj.repeats == -1:
|
||||||
|
color_code = 'C20000'
|
||||||
|
|
||||||
|
html = '<span style="color: #{};font-size:32px">{}</span>'.format(color_code, "*")
|
||||||
|
return format_html(html)
|
||||||
|
|
||||||
|
def calc(self, obj):
|
||||||
|
color_code = "000000"
|
||||||
|
if obj.weight == -1:
|
||||||
|
color_code = 'C20000'
|
||||||
|
|
||||||
|
html = '<span style="color: #{};font-size:32px">{}</span>'.format(color_code, "*")
|
||||||
|
return format_html(html)
|
||||||
|
|
||||||
|
actions = [copy_attributes, select_max_repeat, select_weight_calc]
|
||||||
|
|
||||||
|
|
||||||
class TranslationTrainingPlanInline(admin.TabularInline):
|
class TranslationTrainingPlanInline(admin.TabularInline):
|
||||||
model = TrainingPlanTranslation
|
model = TrainingPlanTranslation
|
||||||
fields = ('language_code', 'name_translation', 'description_translation')
|
fields = ('language_code', 'name_translation', 'description_translation')
|
||||||
@ -17,7 +96,8 @@ class TrainingPlanAdmin(admin.ModelAdmin):
|
|||||||
list_editable = ('name', 'internal_name', 'free', 'active')
|
list_editable = ('name', 'internal_name', 'free', 'active')
|
||||||
|
|
||||||
inlines = [
|
inlines = [
|
||||||
TranslationTrainingPlanInline
|
TranslationTrainingPlanInline,
|
||||||
|
TrainingPlanDetailInline
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@ -99,5 +179,5 @@ class TrainingPlanDetailAdmin(admin.ModelAdmin):
|
|||||||
|
|
||||||
|
|
||||||
admin.site.register(TrainingPlan, TrainingPlanAdmin)
|
admin.site.register(TrainingPlan, TrainingPlanAdmin)
|
||||||
admin.site.register(TrainingPlanDetail, TrainingPlanDetailAdmin)
|
#admin.site.register(TrainingPlanDetail, TrainingPlanDetailAdmin)
|
||||||
admin.autodiscover()
|
admin.autodiscover()
|
||||||
|
@ -95,6 +95,9 @@ class ExerciseTypeAlternative(models.Model):
|
|||||||
exercise_type_child = models.ForeignKey(ExerciseType, on_delete=models.CASCADE,
|
exercise_type_child = models.ForeignKey(ExerciseType, on_delete=models.CASCADE,
|
||||||
related_name='exercise_type_child')
|
related_name='exercise_type_child')
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.exercise_type_parent.name
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
db_table = 'exercise_type_alternative'
|
db_table = 'exercise_type_alternative'
|
||||||
verbose_name = _("Exercise Alternative")
|
verbose_name = _("Exercise Alternative")
|
||||||
|
@ -28,7 +28,7 @@ SECRET_KEY = '9874959872==9847588jkklnkln$asdf' #os.environ['DJANGO_KEY']
|
|||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
|
|
||||||
ALLOWED_HOSTS = ['62.171.188.119', 'localhost', 'andio.eu', 'aitrainer.info','aitrainer.app', 'admin.aitrainer.info']
|
ALLOWED_HOSTS = ['62.171.188.119', 'localhost', 'andio.eu', 'aitrainer.info','aitrainer.app', 'admin.aitrainer.info', "admin.aitrainer.app"]
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user