from django.contrib import admin from django.core.urlresolvers import NoReverseMatch from django.utils.translation import ugettext_lazy as _ from django.template.defaultfilters import slugify from gstudio.admin.forms import AttributeTimeFieldAdminForm import reversion from gstudio.settings import GSTUDIO_VERSIONING if GSTUDIO_VERSIONING == True: parent_class = reversion.VersionAdmin else: parent_class = admin.ModelAdmin class AttributeTimeFieldAdmin(parent_class): fieldsets=((_('AttributeTimeField'),{'fields': ('attributetype','attributetype_scope','subject','subject_scope','svalue','value_scope','value')}), ) prepopulated_fields = {'svalue': ('value', )} def save_model(self, request, attributetimefield, form, change): attributetimefield.title = attributetimefield.composed_sentence attributetimefield.slug = slugify(attributetimefield.title) attributetimefield.save()