mardi 4 août 2015

Django forms extra empty radio button

In rendering a model form an extra radio button is produced and I don't know where it's coming from:

>>> f = DocumentForm()
>>> print f['document_type']
<ul id="id_document_type">
<li><label for="id_document_type_0"><input checked="checked" id="id_document_type_0" name="document_type" type="radio" value="" /> ---------</label></li>
<li><label for="id_document_type_1"><input id="id_document_type_1" name="document_type" type="radio" value="1" /> Campus LAN</label></li>
<li><label for="id_document_type_2"><input id="id_document_type_2" name="document_type" type="radio" value="2" /> WAN</label></li>
<li><label for="id_document_type_3"><input id="id_document_type_3" name="document_type" type="radio" value="3" /> UC</label></li>
</ul>

That first radio button with value="" and the text as ---------, I've scoured my code and can't work out where it originates from?

models.py

class DocumentType(models.Model):
    name = models.CharField("Document Type", max_length=240)

class Document(models.Model):
    document_type = models.ForeignKey(DocumentType,
                                      verbose_name="Document Type")

>>> DocumentType.objects.all()
[<DocumentType: Campus LAN>, <DocumentType: WAN>, <DocumentType: UC>]
>>> d = Document.objects.all()
>>> for x in d:
...     print x.document_type
... 
Campus LAN
Campus LAN



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire