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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:49:57+00:00 2026-06-08T15:49:57+00:00

I’ve been experiencing a little problem when I try to update some record from

  • 0

I’ve been experiencing a little problem when I try to update some record from database.
Strange thing is that form.errors are empty if form is invalid (I can’t understand why).

Here are the

form

class PetitionUpdateForm(forms.ModelForm):
  owner = forms.ModelChoiceField(
    label=_('Petition creator'),
    queryset=User.objects.all(),
    widget=forms.HiddenInput()
  )

  class Meta:
    fields = ('title', 'petition_text', 'description',
              'category', 'num_signs', 'date_to', 'owner',)
    model = Petition

model

class Petition(models.Model):
  PETITION_STATUSES = (
    ('N', _('New petition')), # New one
    ('M', _('Moderation')),   # On moderation
    ('R', _('Rejected')),     # Failed petition
    ('S', _('Success'))       # Succeeded petition
  )

  title = models.CharField(max_length=512)
  slug = models.SlugField(max_length=512, editable=False, blank=True)
  description = models.TextField()
  petition_text = models.TextField(blank=True, null=True)
  petition_picture = models.ImageField(upload_to=get_upload_path, blank=True)
  petitioning = models.ManyToManyField(PetitionTarget, editable=False)
  signs = models.ManyToManyField(User, editable=False, related_name='petition_signs')
  num_signs = models.IntegerField(max_length=11, default=100, blank=True)
  category = models.ForeignKey(Category, blank=True, null=True, related_name='petition_category')
  date_to = models.DateTimeField(blank=True, null=True)

  videos = models.ManyToManyField(Video, editable=False)
  photos = models.ManyToManyField(Photo, editable=False)
  audios = models.ManyToManyField(Audio, editable=False)
  documents = models.ManyToManyField(Document, editable=False)

  created = models.DateTimeField(auto_now_add=True, editable=False)
  changed = models.DateTimeField(auto_now=True, editable=False)
  status = models.CharField(max_length=1, choices=PETITION_STATUSES, default='M', blank=True)
  owner = models.ForeignKey(User, related_name='petition_owner')

  def __unicode__(self):
    return u'{0}: {1}'.format(_('Petition'), self.title)

update view

@login_required
@render_to('petition/edit-petition.html')
def update_petition(request, slug):
  p = get_object_or_404(Petition, slug=slug)
  form = PetitionUpdateForm(request.POST or None, instance=p)
  import pdb
  pdb.set_trace()
  if form.is_valid():
    form.save()
    messages.success(request, _('Petition saved'))
  else:
    print form.errors # errors are empty
    messages.success(request, _('Some error happened'))

  return {'form': form, 'petition': p}

What’s wrong with my code?

I’ve already tried to set null attributes for the most of model fields, switched from class based view to a standard view and yet I’m unable to update my record.

Sultan,

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-06-08T15:49:59+00:00Added an answer on June 8, 2026 at 3:49 pm

    If there is no POST data, then request.POST or None is None, so the form is unbound.

    Unbound forms are always invalid, but do not have any errors.

    In your case, you may want to change the else: clause to elif request.POST:

    See the docs on bound and unbound forms for more details.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I am currently running into a problem where an element is coming back from
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.