Hello everybody hope everybody is doing well.
My question is how do I get a field value (that is not a part of my models) and save that value to a models field?
Below you can see I get the document text but now I want to store it in my models (BEFORE creation) in my model field doc_text.
def create(request):
if request.method == 'POST':
form = forms.CreateBlog(request.POST)
if form.is_valid():
file = request.FILES["doc_text"]
doc_text_str = DocText(file) # HOW DO I ASSIGN THIS VALUE TO MY MODELS (doc_text)
instance = form.save(commit=False)
instance.author = request.user
instance.save()
return redirect('workspace:list')
else:
form = forms.CreateBlog()
return render(request, 'workspace/blog_create.html', {'form':form})
class Blog(models.Model):
author = models.ForeignKey(User, on_delete=models.CASCADE, default="Anonymous")
doc_text = models.TextField(blank=True)
You input/answer would be greatly appreciated! Thanks!