Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6898331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:16:57+00:00 2026-05-27T07:16:57+00:00

I have field in my Model which indicates whether a user wants to receive

  • 0

I have field in my Model which indicates whether a user wants to receive emails

receive_invites = models.BooleanField(default=True, help_text="Receive an invite email from friends")

I also have a view with an option:

[ x ] I do not want to receive emails…

By default receive_invites is True therefore the checkbox is ticked. However, I’d like the user to tick the checkbox in order to change receive_invites to False. I did the following in my ModelForm to achieve this. Does anybody have a more elegant way of doing this?

class UnsubscribeForm(forms.ModelForm):        
    class Meta:
        model = Entrant
        fields = ('receive_invites')

    def __init__(self, *args, **kwargs):
        if kwargs.has_key('instance'):
            instance = kwargs['instance']
            if instance.receive_invites:
                instance.receive_invites = False
            else:
                instance.receive_invites = True
        super(UnsubscribeForm, self).__init__(*args, **kwargs)

and in the view I have this:

if request.method == 'POST':
    unsubscribe_form = UnsubscribeForm(request.POST, instance=me)

    if unsubscribe_form.is_valid():
        receive_invites = unsubscribe_form.cleaned_data['receive_invites']
        if receive_invites:
            user.receive_invites = False
        else:
            user.receive_invites = True
        unsubscribe_form.save()
        return redirect('index')
else:
    unsubscribe_form = UnsubscribeForm(instance=me)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:16:58+00:00Added an answer on May 27, 2026 at 7:16 am

    Adding on to @DrTyrsa, it’s unreasonable to go through so much convolution just to follow a field naming convention. If you’re attached to that field name, you can always add a property to the model that maps the data field to a value you care about:

    dont_receive_invites = models.BooleanField(default=False, help_text="Don't receive an invite email from friends")
    
    @property
    def receive_invites(self):
        return not self.dont_receive_invites
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model which has a date time field: date = models.DateField(_(Date), default=datetime.now())
I have a field type in a model called user which is an int
I have a model which has a field status definde as: class Model(models.Model): ...
I have a model which has a field [DisplayName(Receive occasional email notifications about new
I have model Foo which has field bar. The bar field should be unique,
Say I have a model object 'Person' defined, which has a field called 'Name'.
I have an ActiveRecord model, Foo , which has a name field. I'd like
I have an EntityFramework model which has a boolean field. To make the mapping
I have a notices model which contains records of notices for each user. Each
I have a model which can be attached to to other models. class Attachable(models.Model):

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.