Add in_game_name field to FriendCode model

This commit is contained in:
badblocks 2025-03-14 09:50:49 -07:00
parent 4792906907
commit bc181b12d9
19 changed files with 113 additions and 56 deletions

View file

@ -2,6 +2,7 @@ from django import forms
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from .models import CustomUser, FriendCode
from allauth.account.forms import SignupForm
from crispy_tailwind.tailwind import CSSContainer
class CustomUserChangeForm(UserChangeForm):
@ -12,7 +13,7 @@ class CustomUserChangeForm(UserChangeForm):
class FriendCodeForm(forms.ModelForm):
class Meta:
model = FriendCode
fields = ["friend_code"]
fields = ["friend_code", "in_game_name"]
def clean_friend_code(self):
friend_code = self.cleaned_data.get("friend_code", "").strip()
@ -30,12 +31,32 @@ class CustomUserCreationForm(SignupForm):
model = CustomUser
fields = ['email', 'username', 'friend_code']
email = forms.EmailField(
required=True,
label="Email",
widget=forms.TextInput(attrs={'placeholder': 'Email', 'class':'dark:bg-base-100'})
)
username = forms.CharField(
max_length=24,
required=True,
label="Username",
widget=forms.TextInput(attrs={'placeholder': 'Username', 'class':'dark:bg-base-100'})
)
friend_code = forms.CharField(
max_length=19,
required=True,
label="Friend Code",
help_text="Enter your friend code in the format XXXX-XXXX-XXXX-XXXX.",
widget=forms.TextInput(attrs={'placeholder': 'XXXX-XXXX-XXXX-XXXX'})
widget=forms.TextInput(attrs={'placeholder': 'XXXX-XXXX-XXXX-XXXX', 'class':'dark:bg-base-100'})
)
in_game_name = forms.CharField(
max_length=16,
required=True,
label="In-Game Name",
help_text="Enter your in-game name.",
widget=forms.TextInput(attrs={'placeholder': 'In-Game Name', 'class':'dark:bg-base-100'})
)
def __init__(self, *args, **kwargs):

View file

@ -1,4 +1,4 @@
# Generated by Django 5.1.2 on 2025-03-13 01:46
# Generated by Django 5.1.2 on 2025-03-14 05:35
import django.contrib.auth.models
import django.contrib.auth.validators
@ -48,6 +48,7 @@ class Migration(migrations.Migration):
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('friend_code', models.CharField(max_length=19)),
('in_game_name', models.CharField(max_length=16)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='friend_codes', to=settings.AUTH_USER_MODEL)),

View file

@ -27,6 +27,7 @@ class CustomUser(AbstractUser):
class FriendCode(models.Model):
friend_code = models.CharField(max_length=19)
in_game_name = models.CharField(max_length=16, null=False, blank=False)
user = models.ForeignKey(CustomUser, on_delete=models.PROTECT, related_name='friend_codes')
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)

View file

@ -89,7 +89,7 @@ class DeleteFriendCodeView(LoginRequiredMixin, DeleteView):
return redirect(self.success_url)
# Also check if this friend code is referenced by any trade offer.
if self.object.initiated_by.exists() or self.object.accepted_by.exists():
if self.object.initiated_trade_offers.exists() or self.object.trade_acceptances.exists():
messages.error(
request,
"Cannot remove this friend code because there are existing trade offers associated with it."