Last active
December 22, 2015 22:59
-
-
Save TheBB/6543965 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MatchForm(forms.ModelForm): | |
def __init__(self, *args, **kwargs): | |
super(MatchForm, self).__init__(*args, **kwargs) | |
q = Q(closed=False, lft=F('rgt')-1) | |
if self.instance.eventobj != None: | |
q = q | Q(id=self.instance.eventobj.id) | |
self.fields['eventobj'].queryset = Event.objects.filter(q).order_by('-id') | |
class MessagesInline(admin.StackedInline): | |
model = Message | |
fields = ['type', 'title', 'text'] | |
extra = 1 | |
class MatchAdmin(admin.ModelAdmin): | |
list_display = ('date', 'get_res', match_period, 'treated', 'offline', 'game', 'eventobj', 'submitter') | |
exclude = ('eventobj',) | |
inlines = [MessagesInline] | |
form = MatchForm | |
def get_res(self, obj): | |
return '%s %i-%i %s' % (str(obj.pla), obj.sca, obj.scb, str(obj.plb)) | |
get_res.short_description = 'Result' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment