On 15 mar, 19:38, "Rubic" <[EMAIL PROTECTED]> wrote:
> On Mar 15, 10:06 am, "Grupo Django" <[EMAIL PROTECTED]> wrote:
>
> > Hello, I think I have seen some way to fill aselectfield with data
> > from a table, but I'm not 100% sure and I can't find it anywhere. Is
> > it possible?
>
> ## models.py ##
> from django.db import models
>
> class Team(models.Model):
>     name = models.CharField(maxlength=20)
>     active = models.BooleanField(default=True)
>
> ## views.py ##
> from django import newforms as forms
>
> class TeamForm(forms.Form):
>     teams = [(e.id, e.name) for e in Team.objects.order_by('name') if
> e.active]
>     team_id = forms.ChoiceField(required=False, choices=[('','')]
> +teams)
>
> --
> If you need more dynamically table-based choices:
>
>    http://www.djangosnippets.org/snippets/26/
>    http://www.djangosnippets.org/snippets/49/
> --
> Jeff Bauer
> Rubicon, Inc.
Thank you very much!
Now I want to save the data in a database, how can I do it? I have
this form model:
        categoria = forms.ChoiceField(required=False,
choices=[('','Seleccione una categoria')]+categorias)
        fecha_inicio_publicacion = forms.DateField(input_formats=['%d/
%m/%Y'])
        fecha_fin_publicacion = forms.DateField(input_formats=['%d/%m/
%Y'],required=False)
        titulo = forms.CharField()
        resumen = forms.CharField(widget=forms.Textarea)
        contenido = forms.CharField(widget=forms.Textarea)

if request.POST:
      (save the form)

How can I save it? I'm sorry, I really need to learn a lot, I know it,
I hope you can help me.

Note: I can't use "form_for_model" because it doesn't validate the
date fields all right.
Thank you!


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to