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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:53:35+00:00 2026-05-27T22:53:35+00:00

Django keeps throwing the following when I try and save the addition of two

  • 0

Django keeps throwing the following when I try and save the addition of two object attributes.

invalid literal for int() with base 10: ''

The view is:

def buy_pack(request, pack_name):
if request.method == 'POST':
    form = CardForm(request.POST, request.user)
    pack = Pack.objects.get(name=pack_name)
    stripe_user = request.user.username

    if form.is_valid():
        token = request.POST['stripeToken']
        charge = stripe.Charge.create(
            amount=pack.cost,
            currency="usd",
            card=token,
            description=stripe_user+"_"+pack.name,
        )

        datestring = charge.created
        dt = datetime.datetime.fromtimestamp(float(datestring))
        new_purchase = Purchase(user=request.user, date_time=dt, pack=pack, payment_id=charge.id, last_4_digits=charge.card.last4)
        new_purchase.save()

        user_profile = request.user.get_profile()
        t = user_profile.videos_remaining + pack.videos_allowed
        user_profile.videos_remaining = t
        user_profile.save()

The models in question are:

class UserProfile(models.Model):
    user = models.ForeignKey(User, unique=True)
    name = models.CharField(max_length=50)
    videos_remaining = models.IntegerField(default=1)
    last_4_digits = models.IntegerField(max_length=4, blank=True)
    stripe_id = models.CharField(max_length=255, blank=True)

    def __unicode__(self):
        return self.name

And:

class Pack(models.Model):
    name = models.CharField(max_length=25)
    videos_allowed = models.IntegerField()
    cost = models.IntegerField()

    def __unicode__(self):
        return self.name

Traceback is:

Traceback:
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/Users/Jeff/Dropbox/xxxxx/Code/thankyouvid/../thankyouvid/main/views.py" in buy_pack
  48.           user_profile.save()
File "/Library/Python/2.7/site-packages/django/db/models/base.py" in save
  460.         self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/Library/Python/2.7/site-packages/django/db/models/base.py" in save_base
  526.                         rows = manager.using(using).filter(pk=pk_val)._update(values)
File "/Library/Python/2.7/site-packages/django/db/models/query.py" in _update
  491.         return query.get_compiler(self.db).execute_sql(None)
File "/Library/Python/2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
  869.         cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)
File "/Library/Python/2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
  725.             sql, params = self.as_sql()
File "/Library/Python/2.7/site-packages/django/db/models/sql/compiler.py" in as_sql
  834.                 val = field.get_db_prep_save(val, connection=self.connection)
File "/Library/Python/2.7/site-packages/django/db/models/fields/subclassing.py" in inner
  28.             return func(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/db/models/fields/subclassing.py" in inner
  28.             return func(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/db/models/fields/__init__.py" in get_db_prep_save
  276.         return self.get_db_prep_value(value, connection=connection, prepared=False)
File "/Library/Python/2.7/site-packages/django/db/models/fields/subclassing.py" in inner
  53.             return func(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/db/models/fields/subclassing.py" in inner
  53.             return func(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/db/models/fields/__init__.py" in get_db_prep_value
  271.             value = self.get_prep_value(value)
File "/Library/Python/2.7/site-packages/django/db/models/fields/__init__.py" in get_prep_value
  876.         return int(value)

Exception Type: ValueError at /buy_pack/most/
Exception Value: invalid literal for int() with base 10: ''

For reference the stored value for user_profile.videos_remaining is 1 and the stored value for pack.videos_allowed is 100. I am expecting it to add the two values together and store them as 101 in the user_profile.videos_remaining object attribute.

If you can provide any help I would greatly appreciate it.

EDIT: The problem ended up being that I was not passing a value for the integer field last_4_digits. It seems that this happens if you have a integerField with blank=True and don’t submit a value for it.

  • 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-27T22:53:35+00:00Added an answer on May 27, 2026 at 10:53 pm

    The problem ended up being that I was not passing a value for the integer field last_4_digits. It seems that this happens if you have a integerField with blank=True and don’t submit a value for it.

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

Sidebar

Related Questions

django guardian https://github.com/lukaszb/django-guardian is a really well written object-level permissions app; and I have
In django, I can render a html template from a view action like this:
As the title described, Django keeps changing my URL from /localhost/ to /127.0.0.1:8080/ which
When I view my Django admin (after firing up the python manage.py runserver command),
I am writing a django app that keeps track of which email addresses are
I'm taking the plunge into iPhone development after about two years working with django.
I have two different django projects say projA and projB , each have its
I have a very small part of a Django site that keeps the state
in django, whenever an error is occured , if we dont keep in try
I have a django project I keep on github. It worked perfectly fine on

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.