Ich habe der folgende Test ...Django testen eine Form gilt, wenn es eine ModelChoiceField enthält
def test_contact_form(self):
form_data = {'name': 'Reiss Johnson',
'email': '[email protected]',
'_type': 'General Enquiry',
'content': 'This is some content'}
form = ContactForm(data=form_data)
self.assertTrue(form.is_valid())
Diese ursprünglich vorging als ‚_type‘ war ein CharField, aber es ist jetzt ein ModelChoiceField & so tut Weiß jemand, warum das scheitert? Ich rate jetzt, den '_type' falsch in das Wörterbuch einzugeben?
Wie kann ich den obigen Test wiederholen?
Meine Form ist wie so ...
class ContactForm(forms.Form):
name = forms.CharField(max_length=50)
email = forms.EmailField()
content = forms.CharField()
_type = forms.ModelChoiceField(queryset=EnquiryType.objects.values_list('text', flat=True), empty_label=None)
Was die Werte für 'EnquiryType' sind? 'GeneralEquiry' ist möglicherweise keine gültige Auswahl, dh es entspricht keinem der Werte für das Abfrage-Set. –
Momentan habe ich 2 'EnquiryType' Objekte, eines hat ein' .text' Attribut von 'General Inquiry' und das andere hat ein 'Request A Call Back' '.text' Attribut. Muss ich das Attribut oder etwas eingeben? –