def update_group(request, id): data = {} try: selected_item = Group.objects.get(pk=id) form = GroupForm(instance=selected_item) except Group.DoesNotExist: raise Http404("This item not exist.") if request.method == 'POST': form = GroupForm(request.POST or None, instance=selected_item) if form.is_valid(): form.save() return HttpResponseRedirect('/group') groups = Group.objects.all() data['id'] = id data['groups'] = groups data['form'] = form return render(request, 'home/group.html', data)
def update_group(request, id): data = {} try: selected_item = Group.objects.get(pk=id) form = GroupForm(instance=selected_item) except Group.DoesNotExist: raise Http404("This item not exist.") if request.method == 'POST': form = GroupForm(request.POST or None, instance=selected_item) if form.is_valid(): form.save() return HttpResponseRedirect('/group') groups = Group.objects.all() data['id'] = id data['groups'] = groups data['form'] = form return render( request, 'home/group.html', data )
def group(request): s = request.session.get('users_id', None) if not s: return HttpResponseRedirect('/auth') if request.method == 'POST': form = GroupForm(request.POST) if form.is_valid(): newdoc = Group() newdoc.users_id = request.POST['users'] newdoc.name = request.POST['name'] request.session['users_id'] = newdoc.users_id newdoc = form.save(commit=False) newdoc.save() form.save_m2m() return HttpResponseRedirect('/group') else: form = GroupForm() groups = Group.objects.all() return render_to_response('home/group.html', { 'groups': groups, 'form': form }, context_instance=RequestContext(request))
def group(request): s = request.session.get('users_id', None) if not s: return HttpResponseRedirect('/auth') if request.method == 'POST': form = GroupForm(request.POST) if form.is_valid(): newdoc = Group() newdoc.users_id = request.POST['users'] newdoc.name = request.POST['name'] request.session['users_id'] = newdoc.users_id newdoc = form.save(commit=False) newdoc.save() form.save_m2m() return HttpResponseRedirect('/group') else: form = GroupForm() groups = Group.objects.all() return render_to_response( 'home/group.html', {'groups': groups, 'form': form}, context_instance=RequestContext(request) )