Adds country for user + improves admin

clubs
Laurent 2 years ago
parent 45813f5d32
commit ac5851e162
  1. 54
      tournaments/admin.py
  2. 4
      tournaments/forms.py
  3. 18
      tournaments/migrations/0025_customuser_country.py
  4. 5
      tournaments/models/custom_user.py
  5. 19
      tournaments/models/match.py

@ -5,36 +5,58 @@ from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from .forms import CustomUserCreationForm, CustomUserChangeForm
class CustomUserAdmin(UserAdmin):
form = CustomUserChangeForm
add_form = CustomUserCreationForm
model = CustomUser
list_display = ['email', 'username', 'umpire_code']
list_display = ['email', 'username', 'is_active']
fieldsets = [
(None, {'fields': ['username', 'email', 'password', 'umpire_code', 'clubs', 'phone', 'first_name', 'last_name', 'licence_id', ]}),
(None, {'fields': ['username', 'email', 'password', 'umpire_code', 'clubs', 'phone', 'first_name', 'last_name', 'licence_id', 'country', ]}),
]
add_fieldsets = [
(
None,
{
"classes": ["wide"],
"fields": ['username', 'email', 'password1', 'password2', 'umpire_code', 'clubs', 'phone', 'first_name', 'last_name', 'licence_id', ],
"fields": ['username', 'email', 'password1', 'password2', 'umpire_code', 'clubs', 'phone', 'first_name', 'last_name', 'licence_id', 'country', ],
},
),
]
class CustomTeamRegistration(admin.ModelAdmin):
model = TeamRegistration
list_display = ['player_names', 'name']
class TeamRegistrationAdmin(admin.ModelAdmin):
list_display = ['player_names', 'name', 'tournament']
class TournamentAdmin(admin.ModelAdmin):
list_display = ['name', 'event', 'is_private', 'start_date']
class TeamScoreAdmin(admin.ModelAdmin):
list_display = ['match', 'team_registration', 'score']
class RoundAdmin(admin.ModelAdmin):
list_display = ['tournament', 'name', 'index', 'parent']
class PlayerRegistrationAdmin(admin.ModelAdmin):
list_display = ['first_name', 'last_name', 'licence_id', 'rank']
class MatchAdmin(admin.ModelAdmin):
list_display = ['__str__', 'round', 'group_stage', 'start_date', 'index']
class GroupStageAdmin(admin.ModelAdmin):
list_display = ['tournament', 'index']
class EventAdmin(admin.ModelAdmin):
list_display = ['name', 'club', 'creation_date', 'creator']
class ClubAdmin(admin.ModelAdmin):
list_display = ['name', 'acronym', 'phone']
admin.site.register(CustomUser, CustomUserAdmin)
admin.site.register(Club)
admin.site.register(Event)
admin.site.register(Round)
admin.site.register(GroupStage)
admin.site.register(Match)
admin.site.register(TeamScore)
admin.site.register(TeamRegistration, CustomTeamRegistration)
admin.site.register(Tournament)
admin.site.register(PlayerRegistration)
admin.site.register(Club, ClubAdmin)
admin.site.register(Event, EventAdmin)
admin.site.register(Round, RoundAdmin)
admin.site.register(GroupStage, GroupStageAdmin)
admin.site.register(Match, MatchAdmin)
admin.site.register(TeamScore, TeamScoreAdmin)
admin.site.register(TeamRegistration, TeamRegistrationAdmin)
admin.site.register(Tournament, TournamentAdmin)
admin.site.register(PlayerRegistration, PlayerRegistrationAdmin)

@ -5,10 +5,10 @@ class CustomUserCreationForm(UserCreationForm):
class Meta:
model = CustomUser
fields = UserCreationForm.Meta.fields + ('umpire_code', 'clubs', 'phone', 'first_name', 'last_name', 'licence_id', )
fields = UserCreationForm.Meta.fields + ('umpire_code', 'clubs', 'phone', 'first_name', 'last_name', 'licence_id', 'country')
class CustomUserChangeForm(UserChangeForm):
class Meta:
model = CustomUser
fields = UserCreationForm.Meta.fields + ('umpire_code', 'clubs', 'phone', 'first_name', 'last_name', 'licence_id',)
fields = UserCreationForm.Meta.fields + ('umpire_code', 'clubs', 'phone', 'first_name', 'last_name', 'licence_id', 'country')

@ -0,0 +1,18 @@
# Generated by Django 4.2.11 on 2024-04-04 08:16
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('tournaments', '0024_rename_loser_round_parent'),
]
operations = [
migrations.AddField(
model_name='customuser',
name='country',
field=models.CharField(blank=True, max_length=40, null=True),
),
]

@ -12,10 +12,7 @@ class CustomUser(AbstractUser):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
licence_id = models.CharField(max_length=10, null=True, blank=True)
country = models.CharField(max_length=40, null=True, blank=True)
def __str__(self):
return self.username
# quels sont les champs qu'on veut absolument lorsque l'on créé un user ?
# first/last name ?
# club ?

@ -20,16 +20,15 @@ class Match(models.Model):
broadcasted = models.BooleanField(default=False)
def __str__(self):
match_name = self.name if self.name else self.backup_name() #"x is greater" if x > y else "y is greater"
items = [match_name, self.formatted_start_date()]
desc = " - ".join(items)
player_names = " / ".join(self.player_names())
if self.round:
return f"{desc} > {player_names}"
elif self.group_stage:
return f"{desc} > {player_names}"
else:
return "--"
return " / ".join(self.player_names())
# player_names = " / ".join(self.player_names())
# if self.round:
# return f"{match_name} > {player_names}"
# elif self.group_stage:
# return f"{match_name} > {player_names}"
# else:
# return "--"
def backup_name(self):
items = []

Loading…
Cancel
Save