Re: Forms Question

2008-11-03 Thread Eric Abrahamsen


On Nov 4, 2008, at 8:14 AM, Robocop wrote:

>
> I'm working with some rather long forms, and i've processed them in a
> pretty basic way.  I read in the post data for every field, then just
> create a new table entry using the form data.
>
> Something like:
> if request.method == 'POST':
>  if form.is_valid():
>var_a = form.cleaned_data['var_a']
>var_b = form.cleaned_data['var_b']
>
>   var_z = form.cleaned_data['var_z']
>   new_model = Model( var_a = var_a, var_b = var_b, ... ,var_z =var_z)
>   new_model.save()
>
> Now that my forms are getting pretty long, i'm wondering if there is a
> faster way to do this.  Does anyone know of any tricks or shortcuts to
> just push a one to one mapping of my modelform to my model into a new
> table in my database?  As always, help is greatly appreciated.

If you're using a real modelform, just call save() on it:

http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-save-method

>
> >


--~--~-~--~~~---~--~~
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: Forms Question

2008-11-03 Thread Robocop

I tried that earlier but i failed terribly at syntax.  Should it be:

f = ModelForm(request.POST)
f.save()


On Nov 3, 5:37 pm, Eric Abrahamsen <[EMAIL PROTECTED]> wrote:
> On Nov 4, 2008, at 8:14 AM, Robocop wrote:
>
>
>
>
>
> > I'm working with some rather long forms, and i've processed them in a
> > pretty basic way.  I read in the post data for every field, then just
> > create a new table entry using the form data.
>
> > Something like:
> > if request.method == 'POST':
> >  if form.is_valid():
> >    var_a = form.cleaned_data['var_a']
> >    var_b = form.cleaned_data['var_b']
> >    
> >   var_z = form.cleaned_data['var_z']
> >   new_model = Model( var_a = var_a, var_b = var_b, ... ,var_z =var_z)
> >   new_model.save()
>
> > Now that my forms are getting pretty long, i'm wondering if there is a
> > faster way to do this.  Does anyone know of any tricks or shortcuts to
> > just push a one to one mapping of my modelform to my model into a new
> > table in my database?  As always, help is greatly appreciated.
>
> If you're using a real modelform, just call save() on it:
>
> http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-sav...
>
>
--~--~-~--~~~---~--~~
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: Forms Question

2008-11-03 Thread [EMAIL PROTECTED]

Yep, you need to do the if is_valid() stuff, but other than the save()
method it works like a normal form, more or less.

On Nov 3, 8:07 pm, Robocop <[EMAIL PROTECTED]> wrote:
> I tried that earlier but i failed terribly at syntax.  Should it be:
>
> f = ModelForm(request.POST)
> f.save()
>
> On Nov 3, 5:37 pm, Eric Abrahamsen <[EMAIL PROTECTED]> wrote:
>
> > On Nov 4, 2008, at 8:14 AM, Robocop wrote:
>
> > > I'm working with some rather long forms, and i've processed them in a
> > > pretty basic way.  I read in the post data for every field, then just
> > > create a new table entry using the form data.
>
> > > Something like:
> > > if request.method == 'POST':
> > >  if form.is_valid():
> > >    var_a = form.cleaned_data['var_a']
> > >    var_b = form.cleaned_data['var_b']
> > >    
> > >   var_z = form.cleaned_data['var_z']
> > >   new_model = Model( var_a = var_a, var_b = var_b, ... ,var_z =var_z)
> > >   new_model.save()
>
> > > Now that my forms are getting pretty long, i'm wondering if there is a
> > > faster way to do this.  Does anyone know of any tricks or shortcuts to
> > > just push a one to one mapping of my modelform to my model into a new
> > > table in my database?  As always, help is greatly appreciated.
>
> > If you're using a real modelform, just call save() on it:
>
> >http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-sav...
--~--~-~--~~~---~--~~
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: Forms Question

2008-11-06 Thread Robocop

So i've just gotten back on this project, and it looks like i'm still
doing something wrong with my forms code.

What i have right now is:
def timesheets_add(request):
  if request.method == 'POST':
form = TimeSheetForm(request.POST)
if form.is_valid():
  form.save()
  return render_to_response("confirmation.html",locals())
   else:
  "some YOU FAILED" code
  else:
form = TimeSheetForm()
return render_to_response("form_page.html", locals())


The error i receive now is "TimeSheetForm has no attribute "save""


--~--~-~--~~~---~--~~
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: Forms Question

2008-11-06 Thread Robocop

Never mind, i finally realized what was so drastically different
between .96 forms and 1.0 forms.  Thanks for the help!

On Nov 6, 4:33 pm, Robocop <[EMAIL PROTECTED]> wrote:
> So i've just gotten back on this project, and it looks like i'm still
> doing something wrong with my forms code.
>
> What i have right now is:
> def timesheets_add(request):
>   if request.method == 'POST':
>     form = TimeSheetForm(request.POST)
>     if form.is_valid():
>       form.save()
>       return render_to_response("confirmation.html",locals())
>    else:
>       "some YOU FAILED" code
>   else:
>     form = TimeSheetForm()
>     return render_to_response("form_page.html", locals())
>
> The error i receive now is "TimeSheetForm has no attribute "save""
--~--~-~--~~~---~--~~
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: forms question

2008-02-14 Thread Michael Newman

This one has been debated over and over. It has been decided that
there will be no more as_...() because it is simple enough to hook
into the class and make your own. Here is the discussion over at
django-devs: 
https://groups.google.com/group/django-developers/browse_thread/thread/e3bcd07da81c3275/6337f9a93167c212

On Feb 14, 4:47 pm, Chris <[EMAIL PROTECTED]> wrote:
> will there ever be an forms.as_div method? tables seems kinda old
> school.
--~--~-~--~~~---~--~~
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: forms question in django 1.1

2010-04-28 Thread Bill Freeman
I do notice that you have 'player_option' in the fields tuple, while
there is no such model field, but instead a field named 'player_options'
(plural).  If that's actually in the source, I'd fix it before looking any
harder.

On Wed, Apr 28, 2010 at 10:32 AM, knight  wrote:
> I have the following form:
>
> class ModuleItemForm2(forms.ModelForm):
>    class Meta:
>        model = Module_item
>        fields = ('title', 'media', 'thumb', 'desc', 'default',
> 'player_option')
>
> The model is:
>
> class Module_item(models.Model):
>    title = models.CharField(max_length=100)
>    layout = models.CharField(max_length=5, choices=LAYOUTS_CHOICE)
>    media = models.CharField(help_text='Media url', max_length=500,
> blank=True, null=True)
>    conserv = models.ForeignKey(Conserv, help_text= 'Redirect to
> Conserv', blank=True, null=True)
>    conserve_section = models.CharField(max_length=100, help_text=
> 'Section within the redirected Conserv', blank=True, null=True)
>    parent = models.ForeignKey('self', help_text='Upper menu.',
> blank=True, null=True)
>    module = models.ForeignKey(Module, blank=True, null=True)
>    thumb = models.FileField(upload_to='sms/module_items/thumbs',
> blank=True, null=True)
>    desc = models.CharField(max_length=500, blank=True, null=True)
>    auto_play = models.IntegerField(help_text='Auto start play
> (miliseconds)', blank=True, null=True)
>    order = models.IntegerField(help_text='Display order', blank=True,
> null=True)
>    depth = models.IntegerField(help_text='The layout depth',
> blank=True, null=True)
>    flow_replace = models.IntegerField(blank=True, null=True)
>    default = models.IntegerField(help_text='The selected sub item
> (Note: Starting from 0)', blank=True, null=True)
>    player_options = models.CharField(max_length=1000, null=True,
> blank=True)
>
> In my view I build form:
>
> module_item_form2 = ModuleItemForm2()
> print module_item_form2
>
> And I get the following error on the print line:
>
> 'NoneType' object has no attribute 'label'
>
> It works fine with django 1.0.2. I see the error only in django 1.1.
>
> Do you have an idea what am I doing wrong?
>
> Regards, Arshavski Alexander.
>
> --
> 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 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 at 
http://groups.google.com/group/django-users?hl=en.



Re: forms question in django 1.1

2010-04-28 Thread knight
Thanks a lot. That's the problem.
As always, my stupid mistake.

On Apr 28, 6:12 pm, Bill Freeman  wrote:
> I do notice that you have 'player_option' in the fields tuple, while
> there is no such model field, but instead a field named 'player_options'
> (plural).  If that's actually in the source, I'd fix it before looking any
> harder.
>
>
>
>
>
> On Wed, Apr 28, 2010 at 10:32 AM, knight  wrote:
> > I have the following form:
>
> > class ModuleItemForm2(forms.ModelForm):
> >    class Meta:
> >        model = Module_item
> >        fields = ('title', 'media', 'thumb', 'desc', 'default',
> > 'player_option')
>
> > The model is:
>
> > class Module_item(models.Model):
> >    title = models.CharField(max_length=100)
> >    layout = models.CharField(max_length=5, choices=LAYOUTS_CHOICE)
> >    media = models.CharField(help_text='Media url', max_length=500,
> > blank=True, null=True)
> >    conserv = models.ForeignKey(Conserv, help_text= 'Redirect to
> > Conserv', blank=True, null=True)
> >    conserve_section = models.CharField(max_length=100, help_text=
> > 'Section within the redirected Conserv', blank=True, null=True)
> >    parent = models.ForeignKey('self', help_text='Upper menu.',
> > blank=True, null=True)
> >    module = models.ForeignKey(Module, blank=True, null=True)
> >    thumb = models.FileField(upload_to='sms/module_items/thumbs',
> > blank=True, null=True)
> >    desc = models.CharField(max_length=500, blank=True, null=True)
> >    auto_play = models.IntegerField(help_text='Auto start play
> > (miliseconds)', blank=True, null=True)
> >    order = models.IntegerField(help_text='Display order', blank=True,
> > null=True)
> >    depth = models.IntegerField(help_text='The layout depth',
> > blank=True, null=True)
> >    flow_replace = models.IntegerField(blank=True, null=True)
> >    default = models.IntegerField(help_text='The selected sub item
> > (Note: Starting from 0)', blank=True, null=True)
> >    player_options = models.CharField(max_length=1000, null=True,
> > blank=True)
>
> > In my view I build form:
>
> > module_item_form2 = ModuleItemForm2()
> > print module_item_form2
>
> > And I get the following error on the print line:
>
> > 'NoneType' object has no attribute 'label'
>
> > It works fine with django 1.0.2. I see the error only in django 1.1.
>
> > Do you have an idea what am I doing wrong?
>
> > Regards, Arshavski Alexander.
>
> > --
> > 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.
>
> --
> 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.

-- 
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 at 
http://groups.google.com/group/django-users?hl=en.