You'll need to look into JavaScript or one of the JS libraries such as JQuery to implement the functionality you want. The JS will fire off a request back to Django to make the update at the moment the box is checked. You can use the same view with some complicated logic, but I would recommend the update be handled as an API call and use a separate URL and view for readability and explicit behavior, especially if that action will be used on multiple pages, but perhaps acting on different objects.
Modifying the object in the template only affects things before they are displayed to the user. One the page is rendered/displayed to the user, Django has no control or influence until another request is made, hence the JS in the local browser asking your Django instance for the update behind the scenes, at which point your view can fire off any Python function you wish. AJAX would be a good search term. -James On Jan 9, 2015 1:25 AM, "Tobias Dacoir" <falc...@gmail.com> wrote: > > I want to know if it is possible to directly modify and save a model > instance in the HTML Template and not via a view and extra URL. > > My user has a Boolean Property, I want to display it as a toggle button on > the website and the user should be able to toggle it on or off without > leaving the website or reloading it. > > class User(AbstractBaseUser, PermissionsMixin): ... autoplay_enabled = > models.BooleanField(default=True) ... > > Is this possible without an extra view or form? > Basically I just need to set > > request.user.autoplay_enabled = False > > (or True) > > and then *save()* it > > If I can't modify the object directly in the HTML template is it at least > possible to just execute a function I have defined somewhere in my Python > code, without having the need to create a new view? > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > Visit this group at http://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/abed6766-0bb5-40d9-a2b3-065e17633937%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/abed6766-0bb5-40d9-a2b3-065e17633937%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciWy4cs95EXVKOnGyvzK2hxUoSERSFeN%2BQGB-MagwSV1ZQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.