In my experience "user_signed_up" signal from allauth and "post_save" from django didn't worked well together. I have email confirmation for original signup process but not for alluth.
So I made a different approach. After a successfull login, all my users redirect to homepage. I made a "get_or_create" method here. It's basically doing same thing as "post_save" and "user_signed_up". With this method I don't need to worry about email confirmations too.
Here is my views code:
from django.views.generic import TemplateView
from .models import UserProfile
class HomePageView(TemplateView):
template_name = 'front/homepage.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
user = self.request.user
if user.is_authenticated:
p, created = UserProfile.objects.get_or_create(user=user)
context['balance'] = p.balance
return context
My models:
from django.db import models
from django.contrib.auth.models import User
class UserProfile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, related_name="user_profile")
balance = models.DecimalField(default=0.00, max_digits=9, decimal_places=2)
class Meta:
verbose_name = "User Card"
verbose_name_plural = "User Cards"
def __str__(self):
return self.user.username