Je reçois une erreur de format pour un champ de formulaire qui n'est pas un champ de formulaire de date. Je ne sais pas pourquoi il me donne une forme de quelque chose sans rapport avec le champ de formulaire que je suis en train de remplir ...Format + Erreur de clé - solde - Django
Voici l'erreur exacte qui montre jusqu'à:
ValidationError at /transfer/
["'0' value has an invalid date format. It must be in YYYY-MM-DD format."]
Request Method: POST
Request URL: http://localhost:8000/transfer/
Django Version: 1.8.6
Exception Type: ValidationError
Exception Value:
["'0' value has an invalid date format. It must be in YYYY-MM-DD format."]
Exception Location: C:\Users\OmarJandali\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\fields\__init__.py in to_python, line 1287
Python Executable: C:\Users\OmarJandali\AppData\Local\Programs\Python\Python36\python.exe
Python Version: 3.6.1
Python Path:
['C:\\Users\\OmarJandali\\Desktop\\opentab\\opentab',
'C:\\Users\\OmarJandali\\AppData\\Local\\Programs\\Python\\Python36\\python36.zip',
'C:\\Users\\OmarJandali\\AppData\\Local\\Programs\\Python\\Python36\\DLLs',
'C:\\Users\\OmarJandali\\AppData\\Local\\Programs\\Python\\Python36\\lib',
'C:\\Users\\OmarJandali\\AppData\\Local\\Programs\\Python\\Python36',
'C:\\Users\\OmarJandali\\AppData\\Local\\Programs\\Python\\Python36\\lib\\site-packages']
Voici le fichier modèles:
class Profile(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE) # server
first_name = models.CharField(max_length=25, default='first')
last_name = models.CharField(max_length=25, default='last')
dob = models.DateField(default='0')
city = models.CharField(max_length=45, default='city') # user
state = models.CharField(max_length=25, default='state')
phone = models.BigIntegerField(default=0) # user
privacy = models.SmallIntegerField(default=1) # user
balance = models.DecimalField(decimal_places=2, max_digits=9, default=0)
created = models.DateTimeField(auto_now_add=True) # server
voici le form.py:
class TransferForm(forms.ModelForm):
acct_choices = (('Tabz', 'Tabz - Username'),
('Wells Fargo', 'Wells Fargo - Username'))
main = forms.TypedChoiceField(
choices=acct_choices
)
transfer = forms.TypedChoiceField(
choices=acct_choices
)
class Meta:
model = Transfers
fields = ['main', 'transfer', 'amount', 'memo']
est la partie ici qui est en train de traiter le f ORM et créer le nouveau profil:
L'erreur est dans les lignes 9-14
if main == 'Tabz':
profiles = Profile.objects.all()
for profile in profiles:
if currentUser == profile.user:
currentProfile = profile
currentProfile.balance = currentProfile.balance - amount
currentProfile.save()
else:
new_balance = amount
new_profile = Profile.objects.create(
user = currentUser,
balance = new_balance,
)
message = 'You have transfered ' + amount + ' from your Tabz account to main account'
new_activity = Acitivty.objects.create(
user = currentUser,
description = message,
status = 1,
category = 1,
)
if transfer == 'Tabz':
profiles = Profile.objects.all()
for profile in profiles:
if currentUser == profile.user:
currentProfile = profile
currentProfile.balance = currentProfile.balance + amount
currentProfile.save()
else:
new_balance = amount
new_profile = Profile.objects.create(
user = currentUser,
balance = new_balance
)
message = 'You have transfered ' + amount + ' from your Tabz account to main account'
new_activity = Acitivty.objects.create(
user = currentUser,
description = message,
status = 1,
category = 1,
)
return redirect('home_page')
La valeur par défaut pour 'models.DateField()' doit être un objet 'datetime.date', pas une chaîne. –