Issue
i am trying to save image in django, but it seems not to be working as expected and i can't really tell what is going with the code. the the way i am submitting the form is not a straight forward way of doing form.save
but i am trying to create a topic, if there is no existing topic from the drop down, other informations get saved but the image does not get saved.
views.py
@login_required
def CreateRoom(request):
topics = Topic.objects.all()
if request.method == "POST":
form = ChatRoomForm(request.POST, request.FILES)
topic_name = request.POST.get("topic")
topic , created = Topic.objects.get_or_create(name = topic_name )
new_room = Chatroom.objects.create(
...
image = request.POST.get("image" )
...
)
Solution
You must take image from request.FILES, after write this into storage then set image path into your model field
Answered By - Hossein Asadi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.