Friday, May 30, 2014

Re: Django Template - problema

In relacaoconjugetipouniao_form.html

Add this tag...then refresh...

{{ form.fields }}

Should give you more info about what fields are in the form and what widget they are using.

ie. 'tipo_conjuge': django.forms.fields.TypedChoiceField object

Also check your html source in a browser. Sometimes CSS mistakes hide things.

K


On Friday, May 30, 2014 7:40:01 AM UTC-7, ebrockes wrote:
I have the following problem. The field "tipo_conjuge" is not showing as I wanted. Could somebody tell me what is the problem?

Best regards,
Erick


url. py

...
url(r'relacao/(?P<conjuge>\d+)/$', login_required(CreateTipoRelacaoView.as_view()), name='cadastrarRelacaoTipo'),
...


views.py

...
class CreateTipoRelacaoView(CreateView):
    model = RelacaoConjugeTipoUniao
    fields = ['tipo_conjuge','data_inicio','data_fim']

    def form_valid(self, form):
        relacao = get_object_or_404(RelacaoConjuge, id=self.kwargs['relacao'])
        form.instance.relacao = relacao
        return super(CreateTipoRelacaoView, self).form_valid(form)


models.py

class RelacaoConjugeTipoUniao(models.Model):

    TIPO_CONJUGE = (
        ('CA', _('Casados')),
        ('UE', _('União estável')),
        ('OU', _('Outros')),
    )

    tipo_conjuge = models.CharField(_('Tipo'), max_length=2, choices=TIPO_CONJUGE, blank=False, null=False)
    data_inicio = models.DateField(_('Data de início'))
    data_fim = models.DateField(_('Data de término'))
   ...


relacaoconjugetipouniao_form.html

{% extends 'pessoa/base_voltar.html' %}
{% block content %}
    <form id="formulario" action="" method="POST">{% csrf_token %}
        {{ form.non_field_errors }}
            <div class="fieldWrapper">
            {{ form.tipo_conjuge.errors }}
            <label for="tipo_conjuge">Tipo de União:</label><br/>
            {{ form.tipo_conjuge }}
        </div><br/>
        <div class="fieldWrapper">
            {{ form.data_inicio.errors }}
            <label for="data_inicio">Data de início:</label><br/>
            {{ form.data_inicio }}
        </div><br/>
        <div class="fieldWrapper">
            {{ form.data_fim.errors }}
            <label for="data_fim">Data de término:</label><br/>
            {{ form.data_fim }}
        </div><br/>
        <input type="submit" value="Salvar" class="button">
        <input type="reset" value="Cancelar" class="button">
    </form>
    <br/>
    <a href="#">Voltar</a>
{% endblock content %}

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2c343d4f-48e4-4e5a-a02f-137edc1b0de2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment