<s> from __future__ import unicode_literals <EOL> from django . contrib import admin <EOL> from django . db . models import Max <EOL> from django . template . context import Context <EOL> from django . template . loader import get_template <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from adminsortable2 . admin import SortableAdminMixin <EOL> from cms . admin . placeholderadmin import PlaceholderAdminMixin , FrontendEditableAdminMixin <EOL> from parler . admin import TranslatableAdmin <EOL> from polymorphic . admin import ( PolymorphicParentModelAdmin , PolymorphicChildModelAdmin , <EOL> PolymorphicChildModelFilter ) <EOL> from shop . admin . product import CMSPageAsCategoryMixin , ProductImageInline <EOL> from myshop . models . polymorphic . product import Product <EOL> from myshop . models . polymorphic . commodity import Commodity <EOL> from myshop . models . polymorphic . smartcard import SmartCard <EOL> from myshop . models . polymorphic . smartphone import OperatingSystem , SmartPhone , SmartPhoneModel <EOL> class CommodityAdmin ( SortableAdminMixin , TranslatableAdmin , FrontendEditableAdminMixin , <EOL> PlaceholderAdminMixin , CMSPageAsCategoryMixin , admin . ModelAdmin ) : <EOL> base_model = Product <EOL> fieldsets = ( <EOL> ( None , { <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , ) , <EOL> } ) , <EOL> ( _ ( "<STR_LIT>" ) , { <EOL> '<STR_LIT>' : ( '<STR_LIT:description>' , ) <EOL> } ) , <EOL> ( _ ( "<STR_LIT>" ) , { <EOL> '<STR_LIT>' : ( '<STR_LIT>' , ) <EOL> } ) , <EOL> ) <EOL> filter_horizontal = ( '<STR_LIT>' , ) <EOL> inlines = ( ProductImageInline , ) <EOL> prepopulated_fields = { '<STR_LIT>' : ( '<STR_LIT>' , ) } <EOL> class SmartCardAdmin ( SortableAdminMixin , TranslatableAdmin , FrontendEditableAdminMixin , <EOL> CMSPageAsCategoryMixin , PlaceholderAdminMixin , PolymorphicChildModelAdmin ) : <EOL> base_model = Product <EOL> fieldsets = ( <EOL> ( None , { <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , ) , <EOL> } ) , <EOL> ( _ ( "<STR_LIT>" ) , { <EOL> '<STR_LIT>' : ( '<STR_LIT:description>' , ) <EOL> } ) , <EOL> ( _ ( "<STR_LIT>" ) , { <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , ) <EOL> } ) , <EOL> ) <EOL> filter_horizontal = ( '<STR_LIT>' , ) <EOL> inlines = ( ProductImageInline , ) <EOL> prepopulated_fields = { '<STR_LIT>' : ( '<STR_LIT>' , ) } <EOL> @ admin . register ( OperatingSystem ) <EOL> class OperatingSystemAdmin ( admin . ModelAdmin ) : <EOL> pass <EOL> class SmartPhoneInline ( admin . TabularInline ) : <EOL> model = SmartPhone <EOL> extra = <NUM_LIT:0> <EOL> class SmartPhoneAdmin ( SortableAdminMixin , TranslatableAdmin , FrontendEditableAdminMixin , <EOL> CMSPageAsCategoryMixin , PlaceholderAdminMixin , PolymorphicChildModelAdmin ) : <EOL> base_model = Product <EOL> fieldsets = ( <EOL> ( None , { <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , ) , <EOL> } ) , <EOL> ( _ ( "<STR_LIT>" ) , { <EOL> '<STR_LIT>' : ( '<STR_LIT:description>' , ) <EOL> } ) , <EOL> ( _ ( "<STR_LIT>" ) , { <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> ( '<STR_LIT:width>' , '<STR_LIT>' , '<STR_LIT>' , ) , '<STR_LIT>' ) , <EOL> } ) , <EOL> ) <EOL> filter_horizontal = ( '<STR_LIT>' , ) <EOL> inlines = ( ProductImageInline , SmartPhoneInline , ) <EOL> prepopulated_fields = { '<STR_LIT>' : ( '<STR_LIT>' , ) } <EOL> def save_model ( self , request , obj , form , change ) : <EOL> if not change : <EOL> max_order = self . base_model . objects . aggregate ( max_order = Max ( '<STR_LIT>' ) ) [ '<STR_LIT>' ] <EOL> obj . order = max_order + <NUM_LIT:1> if max_order else <NUM_LIT:1> <EOL> super ( SmartPhoneAdmin , self ) . save_model ( request , obj , form , change ) <EOL> def render_text_index ( self , instance ) : <EOL> template = get_template ( '<STR_LIT>' ) <EOL> return template . render ( Context ( { '<STR_LIT:object>' : instance } ) ) <EOL> render_text_index . short_description = _ ( "<STR_LIT>" ) <EOL> @ admin . register ( Product ) <EOL> class ProductAdmin ( SortableAdminMixin , PolymorphicParentModelAdmin ) : <EOL> base_model = Product <EOL> child_models = ( ( SmartPhoneModel , SmartPhoneAdmin ) , ( SmartCard , SmartCardAdmin ) , ( Commodity , CommodityAdmin ) , ) <EOL> list_display = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , ) <EOL> list_display_links = ( '<STR_LIT>' , ) <EOL> search_fields = ( '<STR_LIT>' , ) <EOL> list_filter = ( PolymorphicChildModelFilter , ) <EOL> list_per_page = <NUM_LIT> <EOL> list_max_show_all = <NUM_LIT:1000> <EOL> def get_price ( self , obj ) : <EOL> return obj . get_real_instance ( ) . get_price ( None ) <EOL> get_price . short_description = _ ( "<STR_LIT>" ) </s>
