in

Django User status not saving during registration


I am using abstract user model. Default is_subscriber value is false is_subscriber = models.BooleanField(default=False). But I am trying to change it ture during registration but I am not understanding why it’s not changing false to ture. here is my code:

models.py

class UserManagement(AbstractUser):
      is_subscriber = models.BooleanField(default=False)


class Subscriber(models.Model):
      user = models.OneToOneField(UserManagement, on_delete=models.CASCADE, primary_key=True)
      email = models.EmailField(max_length=1000) 
      first_name = models.CharField(max_length=200)
      last_name = models.CharField(max_length=200)
      is_subscriber = models.BooleanField(default=False)

forms.py

class SubscriberSignUpForm(UserCreationForm):

      class Meta(UserCreationForm.Meta):
        
           model = UserManagement
           

      @transaction.atomic
      def save(self):
        user = super().save(commit=False)
        user.is_subscriber = True #here I am changing value False to True
        user.save()
        Subscriber.objects.create(
            user=user,
            email=self.cleaned_data.get('email'),
            first_name =self.cleaned_data.get('first_name'),
            last_name =self.cleaned_data.get('last_name'),
            
        )
        my_group = Group.objects.get(name="SubscribersGroup")
        my_group.user_set.add(user) 
        return user

views.py

class SubscriberSignUpView(CreateView):
    model = UserManagement
    form_class = SubscriberSignUpForm
    template_name="members/subscriber-registration.html"

    def get_context_data(self, **kwargs):
        kwargs['user_type'] = 'subscriber'
        return super().get_context_data(**kwargs)

    def form_valid(self, form):
        user = form.save()
 

why is_subscriber status not changing False to True?



Source: https://stackoverflow.com/questions/70543337/django-user-status-not-saving-during-registration

Telcos Might Resort to Another Price Hike After Initiation of Costly 5G Services

Samsung Galaxy A33 5G and Galaxy A13 5G Might Be Launched in India in February 2022