Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » Can I add custom field to ModelForm? [RSS Feed]

#1 Jan. 7, 2011 14:55:49

r.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Can I add custom field to ModelForm?


Is it possible to add field (I want it to be visible in generated form and
after post) to form which is not included in Model? I need it to make a
check after form.is_valid(), but this field won't go to DB.

If yes - how can I do that?

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Jan. 7, 2011 15:01:53

satyandra b.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Can I add custom field to ModelForm?


Hi, i think form choice will work in this case.http://docs.djangoproject.com/en/dev/topics/forms/modelforms/class AuthorForm(forms.Form):
name = forms.CharField(max_length=100)
title = forms.CharField(max_length=3,
widget=forms.Select(choices=TITLE_CHOICES))
birth_date = forms.DateField(required=False)

like here in title, choices=TITLE_CHOICES you can always validate with
clean methods.

I hope it will solve your problem.


On Fri, Jan 7, 2011 at 8:25 PM, robos85 <prog...@gmail.com> wrote:

> Is it possible to add field (I want it to be visible in generated form and
> after post) to form which is not included in Model? I need it to make a
> check after form.is_valid(), but this field won't go to DB.
>
> If yes - how can I do that?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
>http://groups.google.com/group/django-users?hl=en.
>

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Jan. 8, 2011 20:04:38

Brian N.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Can I add custom field to ModelForm?


On Jan 7, 8:55 am, robos85 <prog...@gmail.com> wrote:
> Is it possible to add field (I want it to be visible in generated form and
> after post) to form which is not included in Model? I need it to make a
> check after form.is_valid(), but this field won't go to DB.
>
> If yes - how can I do that?

It is possible. Google for django dynamic forms. The same techniques
can be used for model forms, but you'll have to decide what to do with
the extra fields.

Some links to get you started:http://jacobian.org/writing/dynamic-form-generation/http://www.b-list.org/weblog/2008/nov/09/dynamic-forms/http://www.hindsightlabs.com/blog/2010/02/11/adding-extra-fields-to-a-model-form-in-djangos-admin/Best regards,
BN

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » Can I add custom field to ModelForm? [RSS Feed]

Board footer

Moderator control

Enjoy the 17th of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support