def create(req): UserFormSet = modelformset_factory(User) if req.method == "POST": formset = UserFormSet(req.POST) if formset.is_valid(): user = formset.save()[0] user.set_password(user.password) user.save() # do something. return jsonResponse(serializeUser(user)) else: formset = UserFormSet(queryset=User.objects.none()) return render_to_response("user.html", {"formset": formset}, context_instance=RequestContext(req))
def get(req, user_id): if user_id: user = User.objects.get(id=user_id) return serializeUser(user) else: return [serializeUser(user) for user in User.objects.all()]