Fwd: Django Template - problema

33 views
Skip to first unread message

Erick Brockes

unread,
May 30, 2014, 10:40:01 AM5/30/14
to django...@googlegroups.com
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 %}

Captura de tela de 2014-05-30 11:22:08.png

Kelvin Wong

unread,
May 30, 2014, 5:45:38 PM5/30/14
to django...@googlegroups.com
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

Erick Brockes

unread,
May 30, 2014, 11:12:12 PM5/30/14
to django...@googlegroups.com
Kevin, Thank you.

If you don't mind, I'm kind of new in django.

I've got the following response in the browser:

{'tipo_conjuge': <django.forms.fields.TypedChoiceField object at 0xb4dcb7ec>}

Could you help me out on how to proceed?


--
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...@googlegroups.com.
To post to this group, send email to django...@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.

Erick Brockes

unread,
May 30, 2014, 11:35:58 PM5/30/14
to django...@googlegroups.com
Problem solved by replacing on models.py:


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

by


TIPO_CONJUGE = (
        ('CA', _('Casados')),
        ('UE', _('Uniao estavel')),

        ('OU', _('Outros')),
    )

I'll see how to solve this issue. Any clues?

Kelvin Wong

unread,
May 31, 2014, 3:33:15 AM5/31/14
to django...@googlegroups.com
At the very top of the models.py file add:

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

I'm not sure this will work, but it might.

K

Erick Brockes

unread,
May 31, 2014, 12:27:11 PM5/31/14
to django...@googlegroups.com
It worked. Thank you very much


Reply all
Reply to author
Forward
0 new messages