1👍
From the documentation
Also, a model form instance bound to a model object will contain a
self.instance attribute that gives model form methods access to that
specific model instance.
def myview(request):
if request.method == "POST":
form = MyModelForm(request.POST,request.FILES)
# form.instance -- this is the model
0👍
You can simply pass the form object off to the secondary view:
def view_one(request, slug):
if request.method == 'POST':
obj = get_object_or_404(Model, slug=slug)
model_form = MyModelForm(request.POST, instance = obj)
return view_two(request, form=model_form)
def view_two(request, form=None):
if form:
obj = form.save(commit=False)
obj.some_attribute = "Foo"
obj.save()
return render_to_response(...)
- [Answer]-Django Rest Framewrok query problems with sum
- [Answer]-Using django apps vs established apps…security?
- [Answer]-Python string clean up: How can I remove the excess of newlines of a string in python?
- [Answer]-Where to put object creation logic?
- [Answer]-Passing a template variable as input to a hidden form input field
Source:stackexchange.com