Django Form not saving when using a custom field

JamesJGarner

I am writing a django giftcardredeem, everything works apart from after adding my worth of the giftcard I cannot save the value

class GiftCardRedeem(FormView):
    model = GiftCard
    form_class = GiftCardCheck
    template_name = 'site/redeem.html'
    success_url = '/settings/redeem'

    def form_valid(self, form):
        MessageForm = form.save(commit=False)
        one_entry = GiftCard.objects.get(code=form.cleaned_data['code'])
        currentbal = self.request.user.userprofile.balance
        totalbal = int(currentbal) + int(one_entry.worth)
        print self.request.user.userprofile.balance
        totalbal.save()

Error:

'int' object has no attribute 'save'
Craicerjack

.save() is for saving objects not parts of objects/individual fields. Instead of trying to save the value - add the value to the user object and then save that.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Django form field data lost when using custom widget

From Dev

Boolean field not saving in Django form

From Dev

Django: ValueError when saving an instance to a ForeignKey Field

From Dev

Failure when using setattr to add field to Django form class

From Dev

Failure when using setattr to add field to Django form class

From Dev

"Edit user" form not saving custom field "username" in Devise

From Dev

Date not saving to database when using form_for

From Dev

Custom form field for Foreign key model field in Django

From Dev

Django form not saving

From Dev

Django Form Code not saving

From Dev

Django Model Form not saving

From Dev

Saving files to upload field in Django using a Python script

From Dev

Dynamically Add Field to Model Form Using Django

From Dev

django form field as a list, using post

From Dev

How to automatically compress (using custom script) file when saving in emacs?

From Dev

Issue with dynamically populating dropdownlist for a field in django custom user registration form

From Dev

Saving OnetoOne field manually in django

From Dev

Django saving in a model with User field

From Dev

Django: When saving issue

From Dev

Redirecting after saving form on Django

From Dev

Django form not saving with ModelChoiceField - ForeignKey

From Dev

Cancel saving model when using pre_save in django

From Dev

Saving additional information to the database conditionally when using a modelfrom in django

From Dev

NoReverseMatch in Django when using foreignkey field lookup

From Dev

Why Form is not saving the many to many field value

From Dev

changing the field name django uses when display form error messages

From Dev

Django Form Choice Field Value Not Selected when Editing Instance

From Dev

Form Validation Error when a required field is remained blank in django

From Dev

Django : NoReverseMatch at when changing password using form

Related Related

  1. 1

    Django form field data lost when using custom widget

  2. 2

    Boolean field not saving in Django form

  3. 3

    Django: ValueError when saving an instance to a ForeignKey Field

  4. 4

    Failure when using setattr to add field to Django form class

  5. 5

    Failure when using setattr to add field to Django form class

  6. 6

    "Edit user" form not saving custom field "username" in Devise

  7. 7

    Date not saving to database when using form_for

  8. 8

    Custom form field for Foreign key model field in Django

  9. 9

    Django form not saving

  10. 10

    Django Form Code not saving

  11. 11

    Django Model Form not saving

  12. 12

    Saving files to upload field in Django using a Python script

  13. 13

    Dynamically Add Field to Model Form Using Django

  14. 14

    django form field as a list, using post

  15. 15

    How to automatically compress (using custom script) file when saving in emacs?

  16. 16

    Issue with dynamically populating dropdownlist for a field in django custom user registration form

  17. 17

    Saving OnetoOne field manually in django

  18. 18

    Django saving in a model with User field

  19. 19

    Django: When saving issue

  20. 20

    Redirecting after saving form on Django

  21. 21

    Django form not saving with ModelChoiceField - ForeignKey

  22. 22

    Cancel saving model when using pre_save in django

  23. 23

    Saving additional information to the database conditionally when using a modelfrom in django

  24. 24

    NoReverseMatch in Django when using foreignkey field lookup

  25. 25

    Why Form is not saving the many to many field value

  26. 26

    changing the field name django uses when display form error messages

  27. 27

    Django Form Choice Field Value Not Selected when Editing Instance

  28. 28

    Form Validation Error when a required field is remained blank in django

  29. 29

    Django : NoReverseMatch at when changing password using form

HotTag

Archive