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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:11:20+00:00 2026-05-28T02:11:20+00:00

So I have a modelform which I use with a modelformset factory. If I

  • 0

So I have a modelform which I use with a modelformset factory.

If I leave the form class like this, I receive no error:

class CheckinForm(ModelForm):

class Meta:
    model = Checkout
    fields = ('return_date', )


def __init__(self, *args, **kwargs):
    super(CheckinForm, self).__init__(*args, **kwargs)
    self.fields['return_date'].widget = CheckboxInput()

If I add another field, extension to thefields, I get (1048, "Column 'book_id' cannot be null"), BUT, the changes are saved to the database.

Here is my model:

class Checkout(models.Model):
book = models.ForeignKey(Book)
user = models.ForeignKey(User)
checkout_date = models.DateField(auto_now_add = True)
return_date = models.DateField(null = True, blank=True)
extension = models.IntegerField("Extension in days", blank = True, default = 0)

and here is the view that handles the form:

def checkin(request):
c = RequestContext(request, dictionary)
CheckinFormSet = modelformset_factory(Checkout, CheckinForm)
if request.method == "POST":
    data = request.POST.copy()
    for i in range(0, int(data['form-TOTAL_FORMS'])):
        if 'form-' + str(i) + '-return_date' in data:
            data['form-' + str(i) + '-return_date'] = datetime.date.today().isoformat()
        else:
            data['form-' + str(i) + '-return_date'] = ''

    formset = CheckinFormSet(data = data)
    user_form = AutoUserForm(data = data)
    if formset.is_valid():
        c['cool'] = 'cool'
        formset.save()
    else:
        c['err'] = formset.errors
        c['data'] = data
else:
    CheckinFormSet = modelformset_factory(Checkout, CheckinForm)
    user_form = AutoUserForm()
c['user_form'] = user_form
c['form'] = CheckinFormSet
c['context'] = 'checkin'
return render_to_response('lib_admin/checkin.html', {}, c)

I have to go through the form data because for the return_date field I just have a checkbox that the user will tick, and it’ll insert the current date.

This seems really weird to me, especially because the data is saved, even though I receive the IntegrityError.

  • 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-28T02:11:20+00:00Added an answer on May 28, 2026 at 2:11 am

    It isn’t a good idea to use blank=True together with default. It either has value (default) or not (blank), but not both in the same time.

    Solution:

    extension = models.IntegerField("Extension in days", default=0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this: class OrderForm(ModelForm): class Meta: model = Order exclude = ('number',) def
I have the following model and it's form: class Project(models.Model) class ProjectForm(forms.ModelForm) class Meta:
I have a model service and a ModelForm named Service which I use to
Let's say I have this form: class SimpleUploadForm(forms.Form): file = forms.FileField() I have this
I have this model and modelform: class Comment(models.Model): text = models.CharField(max_length=100) def clean_text(self): print
I have a model and form like so: class Image(BaseModel): original = db.BlobProperty() class
I have the following form: class FeaturedVideoForm(ModelForm): featured_video = forms.ModelChoiceField(Video.objects.none() widget=make_select_default, required=False, empty_label='No Featured
I have the following Form: class GuaranteesForm(forms.ModelForm): birth_date = forms.DateField(input_formats=['%d/%m/%Y'], required=True) However if the
I'm new to Django, trying to process some forms. I have this form for
Ok, here is the question. Imagine I have a ModelForm which have only two

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.