|
|
|
|
@ -117,6 +117,7 @@ class EventAdmin(SyncedObjectAdmin): |
|
|
|
|
raw_id_fields = ['related_user', 'creator', 'club'] |
|
|
|
|
ordering = ['-creation_date'] |
|
|
|
|
readonly_fields = ['display_images_preview'] |
|
|
|
|
actions = ['set_club_action'] |
|
|
|
|
|
|
|
|
|
fieldsets = [ |
|
|
|
|
(None, {'fields': ['last_update', 'related_user', 'name', 'club', 'creator', 'creation_date', 'tenup_id']}), |
|
|
|
|
@ -146,6 +147,47 @@ class EventAdmin(SyncedObjectAdmin): |
|
|
|
|
return mark_safe(html) |
|
|
|
|
display_images_preview.short_description = 'Images Preview' |
|
|
|
|
|
|
|
|
|
def set_club_action(self, request, queryset): |
|
|
|
|
"""Action to set club for selected events""" |
|
|
|
|
from django import forms |
|
|
|
|
from django.contrib.admin.widgets import ForeignKeyRawIdWidget |
|
|
|
|
|
|
|
|
|
class ClubSelectionForm(forms.Form): |
|
|
|
|
club = forms.ModelChoiceField( |
|
|
|
|
queryset=Club.objects.all(), |
|
|
|
|
required=True, |
|
|
|
|
label='Club', |
|
|
|
|
help_text='Enter Club ID or use the search icon to find a club', |
|
|
|
|
widget=ForeignKeyRawIdWidget( |
|
|
|
|
Event._meta.get_field('club').remote_field, |
|
|
|
|
self.admin_site |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
if 'apply' in request.POST: |
|
|
|
|
form = ClubSelectionForm(request.POST) |
|
|
|
|
if form.is_valid(): |
|
|
|
|
club = form.cleaned_data['club'] |
|
|
|
|
updated_count = queryset.update(club=club) |
|
|
|
|
self.message_user( |
|
|
|
|
request, |
|
|
|
|
f'Successfully updated {updated_count} event(s) with club: {club.name}', |
|
|
|
|
messages.SUCCESS |
|
|
|
|
) |
|
|
|
|
return None |
|
|
|
|
else: |
|
|
|
|
form = ClubSelectionForm() |
|
|
|
|
|
|
|
|
|
context = { |
|
|
|
|
'form': form, |
|
|
|
|
'events': queryset, |
|
|
|
|
'action_name': 'set_club_action', |
|
|
|
|
'title': 'Set Club for Events', |
|
|
|
|
} |
|
|
|
|
return render(request, 'admin/tournaments/set_club_action.html', context) |
|
|
|
|
|
|
|
|
|
set_club_action.short_description = "Set club for selected events" |
|
|
|
|
|
|
|
|
|
class TournamentAdmin(SyncedObjectAdmin): |
|
|
|
|
list_display = ['display_name', 'event', 'is_private', 'start_date', 'payment', 'creator', 'is_canceled'] |
|
|
|
|
list_filter = [StartDateRangeFilter, 'is_deleted', 'event__creator'] |
|
|
|
|
|