Re: Foreign key in a ModelForm

2015-08-09 Thread durirompepc
Ok, now I've other problem, and it is that in the HTML the *Select* doesn't 
changes the value selected (it is always the first one, *"-"*). Any 
particullary reason for it?

El domingo, 9 de agosto de 2015, 18:51:30 (UTC+2), durir...@gmail.com 
escribió:
>
> Have you created some in that test?
>
>
> Now I realized I forget to add a *setUp* function with the DB rows...
> .__. 
>
> It doesn't matter how many time I pass coding, always the same fails. 
> Thanks both.
>
> El domingo, 9 de agosto de 2015, 17:00:04 (UTC+2), Daniel Roseman escribió:
>>
>> On Saturday, 8 August 2015 12:58:59 UTC+1, durir...@gmail.com wrote:
>>>
>>> I searched in the web for some example of setting a FK in a ModelForm 
>>> (bound and unbound), but the examples I founded didn't worked for me. The 
>>> best thing I think I've is this:
>>>
>>> *forms.py*
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> *class RegistroComentarioForm(ModelForm):def __init__(self, *args, 
>>> **kwargs):super(RegistroComentarioForm, self).__init__(*args, 
>>> **kwargs)# This is supossed to get all rows from a model. A 
>>> "Comentario" has one "CategoriaComentario".# Maybe I should do a 
>>> filter here when I bound data, but the problem is in the tests...
>>> self.fields['categoria'] = ModelChoiceField(
>>> queryset=CategoriaComentario.objects.all().values_list('id', 'nombre'), 
>>>empty_label='...')# bla bla bla Meta bla bla bla 
>>> fields...tests.py*
>>>
>>> class RegistroComentarioFormTestCase(TestCase):
>>> def test_registrar_comentario(self):
>>> # Registro_Comentario_Form_X.
>>> r_c_f_a = RegistroComentarioForm({
>>> # I tried "'categoria': 1", but nothing.
>>> 'enunciado': 'Eres tan fea que sólo te guiñan un ojo los '
>>>  'francotiradores.'
>>> })
>>>
>>> # Here is the problem. This prints:
>>> # 
>>>
>>> # -
>>>
>>> # 
>>>
>>> # >> name="enunciado"
>>> # placeholder="Sólo caracteres alfanuméricos, sin espacios, máx. 
>>> 1000" rows="10">
>>>  # Eres tan fea que sólo te guiñan un ojo los 
>>> francotiradores.
>>>
>>> for campo in r_c_f_a:
>>> print(campo)
>>>
>>> self.assertTrue(r_c_f_a.is_valid())
>>>
>>>
>>> So I don't have any *CategoriaComentario* available. In the docs they 
>>> don't say much about *ModelChoiceField*, so I just don't know what to 
>>> do.
>>>
>>>
>>
>> What makes you think you should have any? Have you created some in that 
>> test? Where?
>> --
>> DR. 
>>
>

-- 
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+unsubscr...@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/a8b405bd-bef8-42b6-8b36-baad0feae947%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Foreign key in a ModelForm

2015-08-09 Thread durirompepc

>
> Have you created some in that test?


Now I realized I forget to add a *setUp* function with the DB rows...
.__. 

It doesn't matter how many time I pass coding, always the same fails. 
Thanks both.

El domingo, 9 de agosto de 2015, 17:00:04 (UTC+2), Daniel Roseman escribió:
>
> On Saturday, 8 August 2015 12:58:59 UTC+1, durir...@gmail.com wrote:
>>
>> I searched in the web for some example of setting a FK in a ModelForm 
>> (bound and unbound), but the examples I founded didn't worked for me. The 
>> best thing I think I've is this:
>>
>> *forms.py*
>>
>>
>>
>>
>>
>>
>>
>>
>> *class RegistroComentarioForm(ModelForm):def __init__(self, *args, 
>> **kwargs):super(RegistroComentarioForm, self).__init__(*args, 
>> **kwargs)# This is supossed to get all rows from a model. A 
>> "Comentario" has one "CategoriaComentario".# Maybe I should do a 
>> filter here when I bound data, but the problem is in the tests...
>> self.fields['categoria'] = ModelChoiceField(
>> queryset=CategoriaComentario.objects.all().values_list('id', 'nombre'), 
>>empty_label='...')# bla bla bla Meta bla bla bla 
>> fields...tests.py*
>>
>> class RegistroComentarioFormTestCase(TestCase):
>> def test_registrar_comentario(self):
>> # Registro_Comentario_Form_X.
>> r_c_f_a = RegistroComentarioForm({
>> # I tried "'categoria': 1", but nothing.
>> 'enunciado': 'Eres tan fea que sólo te guiñan un ojo los '
>>  'francotiradores.'
>> })
>>
>> # Here is the problem. This prints:
>> # 
>>
>> # -
>>
>> # 
>>
>> # > name="enunciado"
>> # placeholder="Sólo caracteres alfanuméricos, sin espacios, máx. 
>> 1000" rows="10">
>>  # Eres tan fea que sólo te guiñan un ojo los 
>> francotiradores.
>>
>> for campo in r_c_f_a:
>> print(campo)
>>
>> self.assertTrue(r_c_f_a.is_valid())
>>
>>
>> So I don't have any *CategoriaComentario* available. In the docs they 
>> don't say much about *ModelChoiceField*, so I just don't know what to do.
>>
>>
>
> What makes you think you should have any? Have you created some in that 
> test? Where?
> --
> DR. 
>

-- 
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+unsubscr...@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/f229ae18-eeba-48f4-87de-f9765c841f4b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Foreign key in a ModelForm

2015-08-09 Thread Daniel Roseman
On Saturday, 8 August 2015 12:58:59 UTC+1, durir...@gmail.com wrote:
>
> I searched in the web for some example of setting a FK in a ModelForm 
> (bound and unbound), but the examples I founded didn't worked for me. The 
> best thing I think I've is this:
>
> *forms.py*
>
>
>
>
>
>
>
>
> *class RegistroComentarioForm(ModelForm):def __init__(self, *args, 
> **kwargs):super(RegistroComentarioForm, self).__init__(*args, 
> **kwargs)# This is supossed to get all rows from a model. A 
> "Comentario" has one "CategoriaComentario".# Maybe I should do a 
> filter here when I bound data, but the problem is in the tests...
> self.fields['categoria'] = ModelChoiceField(
> queryset=CategoriaComentario.objects.all().values_list('id', 'nombre'), 
>empty_label='...')# bla bla bla Meta bla bla bla 
> fields...tests.py*
>
> class RegistroComentarioFormTestCase(TestCase):
> def test_registrar_comentario(self):
> # Registro_Comentario_Form_X.
> r_c_f_a = RegistroComentarioForm({
> # I tried "'categoria': 1", but nothing.
> 'enunciado': 'Eres tan fea que sólo te guiñan un ojo los '
>  'francotiradores.'
> })
>
> # Here is the problem. This prints:
> # 
>
> # -
>
> # 
>
> #  name="enunciado"
> # placeholder="Sólo caracteres alfanuméricos, sin espacios, máx. 
> 1000" rows="10">
>  # Eres tan fea que sólo te guiñan un ojo los 
> francotiradores.
>
> for campo in r_c_f_a:
> print(campo)
>
> self.assertTrue(r_c_f_a.is_valid())
>
>
> So I don't have any *CategoriaComentario* available. In the docs they 
> don't say much about *ModelChoiceField*, so I just don't know what to do.
>
>

What makes you think you should have any? Have you created some in that 
test? Where?
--
DR. 

-- 
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+unsubscr...@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/a14390fd-eef1-4355-af39-7bd49fa44c5b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Foreign key in a ModelForm

2015-08-09 Thread durirompepc
I get the same, an empty select.


El sábado, 8 de agosto de 2015, 22:49:19 (UTC+2), James Schneider escribió:
>
> Try removing the .values_list() portion of the query set in your 
> ModelForm. You should be passing a query set, not a list of values. The 
> form knows how to iterate through the query set. 
>
> -James
> On Aug 8, 2015 4:59 AM,  wrote:
>
>> I searched in the web for some example of setting a FK in a ModelForm 
>> (bound and unbound), but the examples I founded didn't worked for me. The 
>> best thing I think I've is this:
>>
>> *forms.py*
>>
>>
>>
>>
>>
>>
>>
>>
>> *class RegistroComentarioForm(ModelForm):def __init__(self, *args, 
>> **kwargs):super(RegistroComentarioForm, self).__init__(*args, 
>> **kwargs)# This is supossed to get all rows from a model. A 
>> "Comentario" has one "CategoriaComentario".# Maybe I should do a 
>> filter here when I bound data, but the problem is in the tests...
>> self.fields['categoria'] = ModelChoiceField(
>> queryset=CategoriaComentario.objects.all().values_list('id', 'nombre'), 
>>empty_label='...')# bla bla bla Meta bla bla bla 
>> fields...tests.py*
>>
>> class RegistroComentarioFormTestCase(TestCase):
>> def test_registrar_comentario(self):
>> # Registro_Comentario_Form_X.
>> r_c_f_a = RegistroComentarioForm({
>> # I tried "'categoria': 1", but nothing.
>> 'enunciado': 'Eres tan fea que sólo te guiñan un ojo los '
>>  'francotiradores.'
>> })
>>
>> # Here is the problem. This prints:
>> # 
>>
>> # -
>>
>> # 
>>
>> # > name="enunciado"
>> # placeholder="Sólo caracteres alfanuméricos, sin espacios, máx. 
>> 1000" rows="10">
>>  # Eres tan fea que sólo te guiñan un ojo los 
>> francotiradores.
>>
>> for campo in r_c_f_a:
>> print(campo)
>>
>> self.assertTrue(r_c_f_a.is_valid())
>>
>>
>> So I don't have any *CategoriaComentario* available. In the docs they 
>> don't say much about *ModelChoiceField*, so I just don't know what to do.
>>
>> -- 
>> 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/bfdaa10a-cacb-4c00-9058-c5f28585f74e%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
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+unsubscr...@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/a41d7bac-fc7c-494d-951c-990d39b18728%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Foreign key in a ModelForm

2015-08-08 Thread James Schneider
Try removing the .values_list() portion of the query set in your ModelForm.
You should be passing a query set, not a list of values. The form knows how
to iterate through the query set.

-James
On Aug 8, 2015 4:59 AM,  wrote:

> I searched in the web for some example of setting a FK in a ModelForm
> (bound and unbound), but the examples I founded didn't worked for me. The
> best thing I think I've is this:
>
> *forms.py*
>
>
>
>
>
>
>
>
> *class RegistroComentarioForm(ModelForm):def __init__(self, *args,
> **kwargs):super(RegistroComentarioForm, self).__init__(*args,
> **kwargs)# This is supossed to get all rows from a model. A
> "Comentario" has one "CategoriaComentario".# Maybe I should do a
> filter here when I bound data, but the problem is in the tests...
> self.fields['categoria'] = ModelChoiceField(
> queryset=CategoriaComentario.objects.all().values_list('id', 'nombre'),
>empty_label='...')# bla bla bla Meta bla bla bla
> fields...tests.py*
>
> class RegistroComentarioFormTestCase(TestCase):
> def test_registrar_comentario(self):
> # Registro_Comentario_Form_X.
> r_c_f_a = RegistroComentarioForm({
> # I tried "'categoria': 1", but nothing.
> 'enunciado': 'Eres tan fea que sólo te guiñan un ojo los '
>  'francotiradores.'
> })
>
> # Here is the problem. This prints:
> # 
>
> # -
>
> # 
>
> #  name="enunciado"
> # placeholder="Sólo caracteres alfanuméricos, sin espacios, máx. 
> 1000" rows="10">
>  # Eres tan fea que sólo te guiñan un ojo los 
> francotiradores.
>
> for campo in r_c_f_a:
> print(campo)
>
> self.assertTrue(r_c_f_a.is_valid())
>
>
> So I don't have any *CategoriaComentario* available. In the docs they
> don't say much about *ModelChoiceField*, so I just don't know what to do.
>
> --
> 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+unsubscr...@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/bfdaa10a-cacb-4c00-9058-c5f28585f74e%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@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/CA%2Be%2BciWyeZS8cD8CEyOVgG%3D-yLyRnYosnxf7JpKvJvSGMSBBAQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.