<s> import re <EOL> from django . contrib import admin <EOL> from django . contrib . auth . models import User <EOL> from django import forms <EOL> import datetime <EOL> from hado . models import * <EOL> from hado . forms import * <EOL> from hado . admin_site import HackdoAdmin <EOL> hdadmin = HackdoAdmin ( ) <EOL> class PaymentInline ( admin . TabularInline ) : <EOL> model = Payment <EOL> form = PaymentFormAdmin <EOL> extra = <NUM_LIT:1> <EOL> fields = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def formfield_for_foreignkey ( self , db_field , request , ** kwargs ) : <EOL> if db_field . name == "<STR_LIT>" : <EOL> m = re . search ( "<STR_LIT>" , request . path_info ) <EOL> if m is not None : <EOL> user_id = m . group ( '<STR_LIT:id>' ) <EOL> kwargs [ "<STR_LIT>" ] = Contract . objects . filter ( user__id = user_id ) <EOL> return db_field . formfield ( ** kwargs ) <EOL> return super ( PaymentInline , self ) . formfield_for_foreignkey ( db_field , <EOL> request , <EOL> ** kwargs ) <EOL> class TierInline ( admin . TabularInline ) : <EOL> model = Tier <EOL> class ContractInline ( admin . TabularInline ) : <EOL> model = Contract <EOL> extra = <NUM_LIT:0> <EOL> inlines = [ PaymentInline , ] <EOL> class PaymentAdmin ( admin . ModelAdmin ) : <EOL> form = PaymentFormAdmin <EOL> fieldsets = ( <EOL> ( None , { <EOL> '<STR_LIT>' : ( '<STR_LIT:user>' , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> } ) , <EOL> ) <EOL> def formfield_for_foreignkey ( self , db_field , request , ** kwargs ) : <EOL> if db_field . name == "<STR_LIT>" : <EOL> m = re . search ( "<STR_LIT>" , request . path_info ) <EOL> if m is not None : <EOL> pid = m . group ( '<STR_LIT:id>' ) <EOL> kwargs [ "<STR_LIT>" ] = Contract . objects . filter ( <EOL> user__id = Payment . objects . get ( id = pid ) . user_id ) <EOL> kwargs [ '<STR_LIT>' ] = None <EOL> return db_field . formfield ( ** kwargs ) <EOL> return super ( PaymentAdmin , self ) . formfield_for_foreignkey ( db_field , <EOL> request , <EOL> ** kwargs ) <EOL> class ContractAdmin ( admin . ModelAdmin ) : <EOL> inlines = [ PaymentInline , ] <EOL> class UserAdmin ( admin . ModelAdmin ) : <EOL> list_display = ( '<STR_LIT>' , '<STR_LIT:email>' ) <EOL> list_display_links = ( '<STR_LIT>' , ) <EOL> inlines = [ ContractInline , PaymentInline ] <EOL> fieldsets = ( <EOL> ( None , { <EOL> '<STR_LIT>' : ( '<STR_LIT:username>' , ( '<STR_LIT>' , '<STR_LIT>' ) , '<STR_LIT:email>' ) <EOL> } ) , <EOL> ) <EOL> hdadmin . register ( User , UserAdmin ) <EOL> hdadmin . register ( ContractType ) <EOL> hdadmin . register ( Contract , ContractAdmin ) <EOL> hdadmin . register ( Tier ) <EOL> hdadmin . register ( Payment , PaymentAdmin ) </s>
