Skip to content

Instantly share code, notes, and snippets.

@TheBB
Last active December 22, 2015 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheBB/6543965 to your computer and use it in GitHub Desktop.
Save TheBB/6543965 to your computer and use it in GitHub Desktop.
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