<s> from core . admin import ReadOnlyAwareAdmin , SliceInline <EOL> from core . middleware import get_request <EOL> from core . models import User <EOL> from django import forms <EOL> from django . contrib import admin <EOL> from services . exampleservice . models import * <EOL> class ExampleServiceForm ( forms . ModelForm ) : <EOL> class Meta : <EOL> model = ExampleService <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( ExampleServiceForm , self ) . __init__ ( * args , ** kwargs ) <EOL> if self . instance : <EOL> self . fields [ '<STR_LIT>' ] . initial = self . instance . service_message <EOL> def save ( self , commit = True ) : <EOL> self . instance . service_message = self . cleaned_data . get ( '<STR_LIT>' ) <EOL> return super ( ExampleServiceForm , self ) . save ( commit = commit ) <EOL> class ExampleServiceAdmin ( ReadOnlyAwareAdmin ) : <EOL> model = ExampleService <EOL> verbose_name = SERVICE_NAME_VERBOSE <EOL> verbose_name_plural = SERVICE_NAME_VERBOSE_PLURAL <EOL> form = ExampleServiceForm <EOL> inlines = [ SliceInline ] <EOL> list_display = ( '<STR_LIT>' , '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> list_display_links = ( '<STR_LIT>' , '<STR_LIT:name>' , '<STR_LIT>' ) <EOL> fieldsets = [ ( None , { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:description>' , ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , ] , <EOL> } ) ] <EOL> readonly_fields = ( '<STR_LIT>' , ) <EOL> user_readonly_fields = [ '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:description>' , ] <EOL> extracontext_registered_admins = True <EOL> suit_form_tabs = ( <EOL> ( '<STR_LIT>' , '<STR_LIT>' , ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , ) , <EOL> ) <EOL> suit_form_includes = ( ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) , <EOL> ) <EOL> def queryset ( self , request ) : <EOL> return ExampleService . get_service_objects_by_user ( request . user ) <EOL> admin . site . register ( ExampleService , ExampleServiceAdmin ) <EOL> class ExampleTenantForm ( forms . ModelForm ) : <EOL> class Meta : <EOL> model = ExampleTenant <EOL> creator = forms . ModelChoiceField ( queryset = User . objects . all ( ) ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( ExampleTenantForm , self ) . __init__ ( * args , ** kwargs ) <EOL> self . fields [ '<STR_LIT>' ] . widget . attrs [ '<STR_LIT>' ] = True <EOL> self . fields [ '<STR_LIT>' ] . initial = SERVICE_NAME <EOL> self . fields [ '<STR_LIT>' ] . queryset = ExampleService . get_service_objects ( ) . all ( ) <EOL> if self . instance : <EOL> self . fields [ '<STR_LIT>' ] . initial = self . instance . creator <EOL> self . fields [ '<STR_LIT>' ] . initial = self . instance . tenant_message <EOL> if ( not self . instance ) or ( not self . instance . pk ) : <EOL> self . fields [ '<STR_LIT>' ] . initial = get_request ( ) . user <EOL> if ExampleService . get_service_objects ( ) . exists ( ) : <EOL> self . fields [ '<STR_LIT>' ] . initial = ExampleService . get_service_objects ( ) . all ( ) [ <NUM_LIT:0> ] <EOL> def save ( self , commit = True ) : <EOL> self . instance . creator = self . cleaned_data . get ( '<STR_LIT>' ) <EOL> self . instance . tenant_message = self . cleaned_data . get ( '<STR_LIT>' ) <EOL> return super ( ExampleTenantForm , self ) . save ( commit = commit ) <EOL> class ExampleTenantAdmin ( ReadOnlyAwareAdmin ) : <EOL> verbose_name = TENANT_NAME_VERBOSE <EOL> verbose_name_plural = TENANT_NAME_VERBOSE_PLURAL <EOL> list_display = ( '<STR_LIT:id>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> list_display_links = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:id>' ) <EOL> fieldsets = [ ( None , { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> } ) ] <EOL> readonly_fields = ( '<STR_LIT>' , '<STR_LIT>' , ) <EOL> form = ExampleTenantForm <EOL> suit_form_tabs = ( ( '<STR_LIT>' , '<STR_LIT>' ) , ) <EOL> def queryset ( self , request ) : <EOL> return ExampleTenant . get_tenant_objects_by_user ( request . user ) <EOL> admin . site . register ( ExampleTenant , ExampleTenantAdmin ) </s>
