Tuesday, August 30, 2011

Re: Model.save() does nothing

That won't be necessary. I found the problem and it was just because I
was to stupid. The problem was not the toggle function for that worked
absolutely as it should. But the function which it redirects to in the
not working case doesn't retrieve the data from the database. Instead
it uses a session variable which, of course, contains the untoggled
value. And later this old value is saved again so that it seems as the
first save didn't work. Quite simple if one looks at the right
function...

So, the problem is solved. But thank you anyway.

On 30 Aug., 01:35, "christian.posta" <christian.po...@gmail.com>
wrote:
> No it shouldn't be dependent on anything like that.
> Im curious to know what the issue is for you. I know this might be a
> pain in the butt, but if you could put together a small sample program
> that demonstrates something like this, I would be more than happy to
> help you debug through it.
>
> On Aug 28, 4:33 am, j0ker <jan.te...@googlemail.com> wrote:
>
>
>
>
>
>
>
> > I'm playing around with Django at the moment and have a strange
> > problem.
>
> > There is a view function which basiclydoesnothingelse than toggle a
> > boolean value in a model field - or at least should do so.
>
> > The field definition:
>
> > class Character(models.Model):
> >     ...
> >     ready = models.BooleanField(default=False)
> >     ...
>
> > The view function:
>
> > @decorators.login_required
> > def character_toggle_ready(request, id):
> >     character = get_object_or_404(Character, pk=id)
> >     character.ready = not character.ready
> >     character.save()
> >     return redirect(request.META.get('HTTP_REFERER', '/accounts/
> > overview'))
>
> > The url conf:
> > urlpatterns = patterns('',
> >     ...
> >     url(r'^character/toggle_ready/(\d+)/$',
> > views.character_toggle_ready),
> >     ...)
>
> > In practice I want to have the ready-value toggled when clicking on a
> > hyperlink on my site. E.g. when clicking on '/character/toggle_ready/
> > 1', the value should be toggled and then the view function should
> > redirect to the page before.
>
> > That works as intended, when I access the view from a template which
> > belongs to the app in which this view is definded. But strangely it
> >doesnot work if the link is in a different app. So, when the toggle-
> > view lies in the app 'accounts', it's no problem when accessing it
> > from a template that's rendered by another view of this app. But when
> > the template comes from the app 'core', it wouldn't save. The
> > redirection still works as a charm and also the object is retrieved
> > and the value is toggled, I've checked that with print-functions. But
> > after the save seems to be before the save.
>
> > Has anybody an idea what the reason for that behavior could be? Is the
> > save-function dependend on the passed request? Or am I overlooking
> > something?

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

No comments:

Post a Comment