Opened 15 years ago
Closed 15 years ago
#11846 closed (invalid)
field check does not wok
Reported by: | ankit | Owned by: | nobody |
---|---|---|---|
Component: | Forms | Version: | 1.1-beta |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
I am having a class which is defined as
class ABC(models.Model): id = models.CharField(max_length=100, primary_key=True) pub = models.ForeignKey(WapUser, null=True) brief_description = models.TextField(null=True,blank=True) status = models.CharField(max_length=12, null=True, help_text='Select the appropriate status and click on save', choices=SITE_STATUS_CHOICES ) created_on = models.DateTimeField(null=True) pub_share = models.DecimalField('site_rev_share',max_digits=4,decimal_places=2,null=True) require_full_size_banner = models.IntegerField("Full Size Banner Ads", choices=BOOLEAN_CHOICES, default = 0,null=True) modified_on = models.DateTimeField(auto_now=True,auto_now_add=True,verbose_name ='Last_modified_on') critical_nfr = models.DecimalField(max_digits=5,decimal_places=3,default='60',help_text='Plesae Enter in the range of (0-100)') class Meta: db_table = u'wap_abc' verbose_name_plural= "ABC" managed = False def __unicode__(self): return self.status def get_absolute_url(self): return "/abc/%i/" % self.id
And form.py looks like
class SiteForm(ModelForm): class Meta: model = ABC reason_for_reject = CharField(widget=forms.Textarea,max_length=500,help_text='Please enter if the reason is not in the list',required=False) def clean(self): cleaned_data = self.cleaned_data newStatus = self.cleaned_data.get('status') id_a = self.cleaned_data.get('id') critical_nfr = self.cleaned_data.get('critical_nfr') if new_pub_share == 0 or new_pub_share >=100: raise forms.ValidationError('You cannot set pub_share either equal to 0% or greater than equal to 100% !') if critical_nfr <0 and critical_nfr is not None: raise forms.ValidationError('You cannot set critical_nfr less than Zero !') if self.instance and self.instance.status=='pending': if newStatus =='activated' or newStatus == 'rejected': if newStatus == 'rejected': if rejection_code is None and new_rejection_reason=='': raise forms.ValidationError('Please select a reason to reject or else write in the box given below !') if rejection_code != None and new_rejection_reason!='': raise forms.ValidationError('You cannot select both, either select a reason or write it !')
now if i enter the value of critical_nfr<0,it gives error but if i give '-0' then it does not give any error.WHy .-0 is not any number
Change History (5)
comment:1 by , 15 years ago
Description: | modified (diff) |
---|---|
Resolution: | → invalid |
Status: | new → closed |
comment:2 by , 15 years ago
But in the DB table it is being stored as -0.I know that this will not have any problem but logically there is no number as -0.Well to overcome this problem i am using abs value while saving
comment:4 by , 15 years ago
Resolution: | invalid |
---|---|
Status: | closed → reopened |
comment:5 by , 15 years ago
Resolution: | → invalid |
---|---|
Status: | reopened → closed |
Note:
See TracTickets
for help on using tickets.
Fixed formatting. PLEASE use preview and follow the Wiki Formatting link to learn how to format things properly.
-0 is a valid decimal as far as Python is concerned:
It's going to behave just like 0 so there shouldn't be any problem with accepting it. Django is not going add additional requirement for "valid decimal" beyond what Python already imposes.
If you want to get rid of the negative sign for display purposes you can always just multiply zero-valued critical_nfr values with themselves to ensure they have positive sign. (If you are determined to reject such entries you can use the is_signed Decimal method to detect the situation: http://docs.python.org/library/decimal.html#decimal.Decimal.is_signed.)