I misunderstand something! If my model is not saved, it does not have an identifier associated with it. Therefore, if I have something like this:
views.py (pasting or editing existing information uses the same model)
def insert_or_modify(request, id=None): if id is not None: book = BookModel.objects.get(pk=id) else: book = BookModel() if request.method == 'POST': form = BookInfoForm(request.POST, request.FILES, instance=book) if form.is_valid(): form.save() .... return render_to_response(...)
I also have an image and use upload_to for the image field. There are two problems: id is None, and I'm not sure how to manipulate / save instance=book so that I really get the identifier. The second problem is that the location where I save my data is far away. Although the book.img.url template book.img.url has the desired book location at http:127.0.0.1:8000/folder1/media/id/ , the actual location is somewhere else:
Where I want to save my image:
/project/folder1/media/id/
where id is the identifier of the book.
What I actually get:
/project/id/
(But 'id' becomes 'None' because it does not exist!)
My previous code worked. It will save in the right place, but this will not work with this current code. So the save problem is not like this because of settings.py, as it worked previously.
EDIT: Remote Necode from Code Formatting Area
EDIT: I found out why I did not save the data in the right place. As it turned out, I forgot to uncomment something the last time I modified settings.py. Saving a location now works! Sorry guys!
EDIT: I think the id = None problem is caused by form.save (). If I do not do this and just save for the model directly, I do not have this problem.