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 4081204
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:01:50+00:00 2026-05-20T18:01:50+00:00

I came across a thread that seemed like it might be related at djangocode

  • 0

I came across a thread that seemed like it might be related at djangocode but it didn’t really help. I’m trying to save a modelform and it’s throwing an exception. I think that it might be related to referring to the same foreign key twice in my model. It might also have to do with the definition of unique=True in one of the foreign key fields. I don’t know

class User_Message(models.Model):
   recipient=models.ForeignKey(User, unique=True, related_name="recipients")
   subject=models.CharField(max_length=100)
   sender=models.ForeignKey(User, related_name="senders")
   message=models.TextField(max_length=500)
sent=models.DateField(auto_now_add=True)

def __unicode__(self):
    return self.subject



if request.method=="POST" and request.POST['id_message']:
    messageform=User_MessageForm(request.POST)
    recipient=[]   #receiver of mail must be a list
    recipient.append(post.user)
    if messageform.is_valid:
        message=messageform.save(commit=False)
        message.sender=user
        message.recipient=post.user
        return HttpResponse('%s %s' %(user,post.user))
        message.save()

        #send the email
        subject=messageform.cleaned_data['id_subject']
        body=messageform.cleaned_data['id_message']

        try:
            send_mail(subject, body, sender, recipient)
        except BadHeaderError:
            return HttpResponse('Invalid header found.')

It’s failing at the line, messageform.save(commit=False). Man I thought that statement was fail proof.

The POST data that is received by the modelform contains the subject and message fields. This data is successfully validated by my modelform.

Is it the related names, the unique=True… what gives?

Thanks

  • 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-20T18:01:51+00:00Added an answer on May 20, 2026 at 6:01 pm

    Here’s your problem:

    if messageform.is_valid:
    

    That line needs to be

    if messageform.is_valid():
    

    Basically, the error comes from calling save() on an invalid form.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I came across this thread when I was looking for a solution, but it
I came across a few articles like this one , which suggest that some
I'm trying to read about Ruby performance, and came across this SO thread ,
I came across this thread: Is there a function like array_merge in PHP in
I came across this thread Node.js HTTPS Secure Error which mentions that the tls
Im currently looking at using min3d but came across a thread where the original
I came across this question on an interview questions thread. Here is the question:
Came across something like this today, and was wondering if there was an equivalent
I came across a piece of code which looks like this: jQuery(function($) { $('#saySomething').click(function()
I came across this thread Turning off coalescing in Nvidia Forum where it is

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.