Compare commits

...

2 Commits

Author SHA1 Message Date
Razmig Sarkissian 240bb3fc25 Add admin template for setting club for multiple events 6 days ago
Razmig Sarkissian 5102e4c295 Add set club bulk action to EventAdmin 6 days ago
  1. 42
      tournaments/admin.py
  2. 66
      tournaments/templates/admin/tournaments/set_club_action.html

@ -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']

@ -0,0 +1,66 @@
{% extends "admin/base_site.html" %}
{% load static %}
{% block extrahead %}
{{ block.super }}
{{ form.media }}
{% endblock %}
{% block content %}
<h1>{{ title }}</h1>
<p>You are about to set the club for the following {{ events|length }} event(s):</p>
<div style="margin: 20px 0; padding: 15px; background-color: #f8f9fa; border: 1px solid #dee2e6; border-radius: 4px;">
<ul style="margin: 0; padding-left: 20px;">
{% for event in events %}
<li>
<strong>{{ event.name }}</strong>
{% if event.club %}
(currently: {{ event.club.name }})
{% else %}
(currently: No club assigned)
{% endif %}
</li>
{% endfor %}
</ul>
</div>
<form method="post">
{% csrf_token %}
<div style="margin: 20px 0;">
<div class="form-row">
{{ form.club.errors }}
<div>
<label for="{{ form.club.id_for_label }}">{{ form.club.label }}:</label>
<div class="help">{{ form.club.help_text }}</div>
{{ form.club }}
</div>
</div>
</div>
<div style="margin-top: 20px;">
<input type="submit" name="apply" value="Set Club" class="button default" style="
background-color: #417690;
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
margin-right: 10px;
"/>
<a href="{% url 'admin:tournaments_event_changelist' %}" class="button" style="
display: inline-block;
padding: 10px 20px;
background-color: #6c757d;
color: white;
text-decoration: none;
border-radius: 4px;
font-size: 14px;
">Cancel</a>
</div>
</form>
{% endblock %}
Loading…
Cancel
Save