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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:10:12+00:00 2026-05-25T11:10:12+00:00

Model and ModelForm in django project are defined like this : class Consumption(models.Model): date=models.DateTimeField(default=datetime.now)

  • 0

Model and ModelForm in django project are defined like this :

class Consumption(models.Model):
    date=models.DateTimeField(default=datetime.now)
    product_name=models.ForeignKey(Stock,to_field='product_name')
    quantity=models.IntegerField()
    customer=models.CharField(max_length=50,null=True,blank=True)

    def __unicode__(self):
        return self.product_name

class ConsumptionForm(ModelForm):
    class Meta:
        model=Consumption

    def clean_quantity(self):
        cleaned_data=self.cleaned_data
        product=cleaned_data.get("product_name")
        quantity=int(cleaned_data.get('quantity'))
        stock=Stock.objects.get(product_name=product)
        if quantity > stock.quantity:
            raise forms.ValidationError("Not enough stock")
        return cleaned_data

where Stock class contains product name which serves as Foreign Key to Consumption and and whose quantity should be greater than consumption quantity.

Now the problem is when I enter submit to ConsumptionForm . It gives me error on quantity field as this field must be an integer even after when I am providing it an integer.

What can be the reason of this?

  • 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-25T11:10:12+00:00Added an answer on May 25, 2026 at 11:10 am

    You’re returning the whole cleaned_data dictionary from the clean_quantity method, rather than just the value of quantity.

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

Sidebar

Related Questions

I have a django model as following class Project(models.Model) name=models.CharField(max_length=200) class Application(models.Model) proj=models.ForeignKey(Project, null=True,
I am using ModelForm on Django 1.3. models.py: class UserProfile(models.Model): ... gender = models.CharField(max_length=1,
I have this model and modelform: class Comment(models.Model): text = models.CharField(max_length=100) def clean_text(self): print
I have a rails model that looks something like this: class Recipe < ActiveRecord::Base
class Tag(models.Model): name = models.CharField(maxlength=100) class Blog(models.Model): name = models.CharField(maxlength=100) tags = models.ManyToManyField(Tag) Simple
I have this Task model: class Task < ActiveRecord::Base acts_as_tree :order => 'sort_order' end
I have django ModelForm for model with ManyToManyField. I want to change widget for
In a Django ModelForm, you can change the widget type of a field like
Is it possible to have multiple models included in a single ModelForm in django?
I currently have a ModelForm set up in Django, but would like to make

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.