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

  • Home
  • SEARCH
  • 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 915241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:51:16+00:00 2026-05-15T17:51:16+00:00

In my user’s data edit form I have a boolean field, for adding/removing email

  • 0

In my user’s data edit form I have a boolean field, for adding/removing email from newsletter. I’ve written a custom save method for this form :

def save(self, *args, **kwargs):      
    mail = None
    if self.cleaned_data['inf_newsletter']:
        mail = NewsletterEmails(self.instance.user.email)
        mail.save() 
    else:
        try:
            mail = NewsletterEmails.objects.get(email=self.instance.user.email)
        except NewsletterEmails.DoesNotExist:
            pass
        if mail:
            mail.delete()

Problem is,that when I’m adding new NewsletterEmail object, I’m sending string value read from user’s email to be saved in email field, which raises error (or at least I think so) :

Traceback:
File "/home/myapp/site-packages/django/core/handlers/base.py" in get_response
  92.                 response = callback(request, *callback_args, **callback_kwargs)
File "/home/myapp/site-packages/django/contrib/auth/decorators.py" in __call__
  78.             return self.view_func(request, *args, **kwargs)
File "/home/myapp/accounts/views.py" in profile_edit
  95.             form.save()
File "/home/myapp/accounts/forms.py" in save
  58.             mail.save() 
File "/home/myapp/site-packages/django/db/models/base.py" in save
  410.         self.save_base(force_insert=force_insert, force_update=force_update)
File "/home/myapp/site-packages/django/db/models/base.py" in save_base
  470.                         manager.filter(pk=pk_val).extra(select={'a': 1}).values('a').order_by())):
File "/home/myapp/site-packages/django/db/models/manager.py" in filter
  129.         return self.get_query_set().filter(*args, **kwargs)
File "/home/myapp/site-packages/django/db/models/query.py" in filter
  498.         return self._filter_or_exclude(False, *args, **kwargs)
File "/home/myapp/site-packages/django/db/models/query.py" in _filter_or_exclude
  516.             clone.query.add_q(Q(*args, **kwargs))
File "/home/myapp/site-packages/django/db/models/sql/query.py" in add_q
  1675.                             can_reuse=used_aliases)
File "/home/myapp/site-packages/django/db/models/sql/query.py" in add_filter
  1614.                 connector)
File "/home/myapp/site-packages/django/db/models/sql/where.py" in add
  56.                 obj, params = obj.process(lookup_type, value)
File "/home/myapp/site-packages/django/db/models/sql/where.py" in process
  269.                 params = self.field.get_db_prep_lookup(lookup_type, value)
File "/home/myapp/site-packages/django/db/models/fields/__init__.py" in get_db_prep_lookup
  210.             return [self.get_db_prep_value(value)]
File "/home/myapp/site-packages/django/db/models/fields/__init__.py" in get_db_prep_value
  361.         return int(value)

Exception Type: ValueError at /user/profile/
Exception Value: invalid literal for int() with base 10: 'foo@bar.com'

My NewsletterEmail model :

class NewsletterEmails(models.Model):
    email = models.EmailField(_(u"Email"),)

How to get around this problem ?

  • 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-15T17:51:17+00:00Added an answer on May 15, 2026 at 5:51 pm
    mail = NewsletterEmails(self.instance.user.email)
    

    You are assigning the inputted email address to the implicitly created primary key field, not the email field.

    Use:

    mail = NewsletterEmails(email=self.instance.user.email)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 508k
  • Answers 508k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer http://packages.python.org/fs/expose/fuse.html you can see what you need from this link.… May 16, 2026 at 4:29 pm
  • Editorial Team
    Editorial Team added an answer This is weird. According to the sources of HibernateProvider#createEntityManagerFactory, the… May 16, 2026 at 4:29 pm
  • Editorial Team
    Editorial Team added an answer Loading the database driver can be done just only once… May 16, 2026 at 4:29 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

My User model contains :name, :email, and :password fields. All 3 have validations for
User A logs into a ticket management system to edit content on SomePage.aspx User
/* user-defined exception class derived from a standard class for exceptions*/ class MyProblem :
User 2 offers to buy an item from User 1 . User 1 can
The user I have should have access to all tables in a database -
The user sees a web form with a bunch of controls. One of them
The user sees a form with many controls, including a list box. He selects
A user enters a date in a form, but when I pass a date
User equals untrustworthy. Never trust untrustworthy user's input. I get that. However, I am
User kokos answered the wonderful Hidden Features of C# question by mentioning the using

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.