Field 'roof_age' expected a number but got ('1',)

2022-09-17 Thread Nishant Sagar
Hey folks,
While saving the values to the data to the database I'm getting this Field
'roof_age' expected a number but got ('1',)

How can I resolve this?
Here is my views.py file

def form(requests):
if requests.method == 'POST':
name=requests.POST['name'],
# roof_age= requests.POST['roof_age'],
roof_age= int(requests.POST.get('roof_age')),
email = requests.POST['email'],
phone = requests.POST['phone'],
address = requests.POST['address'],
monthly_bill = requests.POST['monthly_bill'],
HOA = requests.POST['HOA'],
battery = requests.POST['battery'],
foundation = requests.POST['foundation'],
roof_type = requests.POST['roof_type'],
availability= requests.POST['availability'],
bill = requests.POST['bill']

details = Details(
name = name,
roof_age = roof_age,
email = email,
phone = phone,
address = address,
monthly_bill = monthly_bill,
HOA = HOA,
battery = battery,
foundation = foundation,
roof_type = roof_type,
availability= availability,
bill = bill
)
print(type(roof_age))
print(name, roof_age, email, phone, address, monthly_bill, HOA,battery,
foundation, roof_type, availability, bill)
print("The data has been save to db")
I'm getting data in the form of tuple instead of values

The print statement is giving me output as
('Nishant',) ('nishantsag...@gmail.com',) ('8210574914',) ('Test-1',)
('6',) ('on',) ('on',) ('on',) ('Spanish',) ('2022-09-17T23:38',)
leetcode.cpp

And Even Though I am turning my radio button off I'm still getting values
as on

Here is my models.py file
class Details(models.Model):
name = models.CharField(max_length=25)
roof_age = models.IntegerField()
email = models.EmailField()
phone = models.IntegerField()
address = models.TextField(max_length=100)
monthly_bill = models.IntegerField()
HOA = models.BooleanField(default=True)
battery = models.BooleanField(default=True)
foundation = models.BooleanField(default=True)
roof_type = models.CharField(max_length=20)
availability = models.DateTimeField()
bill = models.FileField(upload_to='uploads/%d/%m/%y/')

class Meta:
verbose_name = 'details'
verbose_name_plural = 'details'

def __str__(self):
return self.name

Thank You

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CANNtL-%2BHu6zaTtBdHC1_9AaJsRq81mms-%3DX8Voxyj9CYgmsPYA%40mail.gmail.com.


Re: Field 'roof_age' expected a number but got ('1',)

2022-09-17 Thread Esteban Chacon Martin
Also take off each comma after the assigment and that should fix it all,
forget about indexing as i recommend before

El sáb, 17 sept 2022 a las 14:38, Esteban Chacon Martin ()
escribió:

> Use requests.POST.get('roof_age')[0] instead, seems to me like you are
> getting a list instead of a string when doing the get
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAA%2BkBvyjeK5wycRV7LeKLQsa9UhX6W0iiJDbzcppnfr516_JYA%40mail.gmail.com.


Re: Field 'roof_age' expected a number but got ('1',)

2022-09-17 Thread Esteban Chacon Martin
Use requests.POST.get('roof_age')[0] instead, seems to me like you are
getting a list instead of a string when doing the get

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAA%2BkBvyo2hqmw%3Dp9EK2gdpCuc0gwUtrSnFD3Qm2jucE%3D2XrJNQ%40mail.gmail.com.


Re: Field 'roof_age' expected a number but got ('1',)

2022-09-17 Thread Nishant Sagar
I really appreciate your help, removing comma has fixed the problem but now
for check boxes and bill (which is file type) I’m getting string output
instead of bool and file

How can I fix that now?

On Sun, 18 Sep 2022 at 1:24 AM, Esteban Chacon Martin 
wrote:

> Also take off each comma after the assigment and that should fix it all,
> forget about indexing as i recommend before
>
> El sáb, 17 sept 2022 a las 14:38, Esteban Chacon Martin (<
> n4b3...@gmail.com>) escribió:
>
>> Use requests.POST.get('roof_age')[0] instead, seems to me like you are
>> getting a list instead of a string when doing the get
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-developers+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/CAA%2BkBvyjeK5wycRV7LeKLQsa9UhX6W0iiJDbzcppnfr516_JYA%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CANNtL-Lp0R-5fv_NnaW6xdR3Gsz5mCv2mWECu2%3DZYnFMruQjXw%40mail.gmail.com.