Re: Populating a form from the database

2009-08-05 Thread Thomas Guettler

Hi,

if you use ModelForm, the data from the database are the initial
form data.

If you create a new record with ModelForm, you could use the "initial"
parameter to supply some default values. More can be found in the docs.

  Thomas

Magnus Valle schrieb:
> Short:
> How do I populate a form with data from the database?
> Fx. if I want to let users edit the data they have entered.
> 
> Long:
> Currently, I have a form where the user(if logged in) will enter data 
> and when it is submitted some extra data is entered to the form before 
> it is saved, a time-stamp and the request.user .
> 
> But is there a way to open the form, looking to see if the user already 
> has entered some data, then populate the form with that data. But if the 
> user does not have a entry in the database, then presenting an empty form. ?


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Populating a form from the database

2009-08-04 Thread Magnus Valle

Short:
How do I populate a form with data from the database?
Fx. if I want to let users edit the data they have entered.

Long:
Currently, I have a form where the user(if logged in) will enter data 
and when it is submitted some extra data is entered to the form before 
it is saved, a time-stamp and the request.user .

But is there a way to open the form, looking to see if the user already 
has entered some data, then populate the form with that data. But if the 
user does not have a entry in the database, then presenting an empty form. ?

--
MV

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



DateField format with a ModelForm: populating the form from a model instance

2008-12-07 Thread alex_t

Hi,

I've written my own view to create / edit model instances my project,
and part of what I wanted to do was to accept dates only in the format
dd-mm- (%d-%m-%Y).

I searched around a bit and came accross this post:
http://groups.google.com/group/django-users/browse_thread/thread/9f84d1b920e54dd2/bbc7857c120c8ecb.
Creating my own model field class seemed pretty extreme, but I quickly
worked out that I can do this much more simply by adding a line to my
ModelForm:

class EventForm(ModelForm):
start_date = forms.DateField(input_formats=['%d-%m-%Y'])

This changes the behaviour, and works fine for validating dates
written in non- US format.


My problem is that when I create an EventForm from a model instance
(for my 'edit' functionality) the date fields (rendered as html text
inputs) are populated in the standard %Y-%m-%d format. Submitting the
form as populated is therefore invalid, so I have to manually play
with the dates each time I edit an event.

How would I go about changing this behaviour? I understand that patch
1.1 might address this (by typing date format to locale), but I would
like to see if I can knock up a temporary solution.

Thanks in advance
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Populating a form

2007-09-13 Thread Peter Melvyn

On 9/13/07, MikeHowarth <[EMAIL PROTECTED]> wrote:

> Look at form_for_instance in newforms:

I am not sure if it could help me. I try to demostrate my problem on
the view fragment handling post request:

form = MyHTMLForm(request.POST)
if not form.is_valid():
  # will render bound form
else:
  try:
 # posted data processing
  except:
 # will render bound form
  else:
 # Here I need to clear some form's fields without generating
 # error in bound form.
 # I suppose it could be done by creating a new unbound instance
 # of MyHTMLForm and passing values I need to retain as initial values
 # from old form instance.
 # But it seems to be ugly solution
...
  response = (,form,)

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Populating a form

2007-09-13 Thread MikeHowarth

Look at form_for_instance in newforms:

http://www.djangoproject.com/documentation/newforms/



On Sep 13, 9:08 am, "Peter Melvyn" <[EMAIL PROTECTED]> wrote:
> On 9/11/07, Ole Laursen <[EMAIL PROTECTED]> wrote:
>
> > You can also use the initial parameter when instantiating the form:
>
> And how to solve situation when you've processed posted data and in
> the next step you need to redisplay the same form with some values
> reset to initial values?
>
> Peter


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Populating a form

2007-09-13 Thread Peter Melvyn

On 9/11/07, Ole Laursen <[EMAIL PROTECTED]> wrote:

> You can also use the initial parameter when instantiating the form:

And how to solve situation when you've processed posted data and in
the next step you need to redisplay the same form with some values
reset to initial values?


Peter

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Populating a form

2007-09-11 Thread Kenneth Gonsalves


On 12-Sep-07, at 10:41 AM, Ahik wrote:

> newforms.

you have to create a dictionary of the data you want in the form  
relating fieldname to the data and bind the form to this - see the  
bound form docs

-- 

regards
kg
http://lawgon.livejournal.com
http://nrcfosshelpline.in/web/



--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Populating a form

2007-09-11 Thread Ahik

newforms.

On Sep 12, 4:05 am, Kenneth Gonsalves <[EMAIL PROTECTED]> wrote:
> On 11-Sep-07, at 11:45 AM, AniNair wrote:
>
> >I am trying to learn python and django.  Can someone please tell me
> > how to populate some fields in a form
>
> newforms or oldforms?
>
> --
>
> regards
> kghttp://lawgon.livejournal.comhttp://nrcfosshelpline.in/web/


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Populating a form

2007-09-11 Thread Kenneth Gonsalves


On 11-Sep-07, at 11:45 AM, AniNair wrote:

>I am trying to learn python and django.  Can someone please tell me
> how to populate some fields in a form

newforms or oldforms?

-- 

regards
kg
http://lawgon.livejournal.com
http://nrcfosshelpline.in/web/



--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Populating a form

2007-09-11 Thread MikeHowarth

You'll need to load an instance of the model, which will pre-populate
the data:

http://www.djangoproject.com/documentation/newforms/#form-for-instance

On Sep 11, 7:15 am, AniNair <[EMAIL PROTECTED]> wrote:
> Hi...
>I am trying to learn python and django.  Can someone please tell me
> how to populate some fields in a form? I want to have certain values
> present in CharField  or Textfield . (Eg:For editing a profile: the
> data previously entered needs to be present in the resp fields...)
> Please help. 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
-~--~~~~--~~--~--~---



Populating a form

2007-09-11 Thread AniNair

Hi...
   I am trying to learn python and django.  Can someone please tell me
how to populate some fields in a form? I want to have certain values
present in CharField  or Textfield . (Eg:For editing a profile: the
data previously entered needs to be present in the resp fields...)
Please help. 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
-~--~~~~--~~--~--~---