Changes between Initial Version and Version 1 of Ticket #32845


Ignore:
Timestamp:
Jun 13, 2021, 12:34:27 PM (3 years ago)
Author:
Jacob Fredericksen
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #32845 – Description

    initial v1  
    11According to the Django docs (https://docs.djangoproject.com/en/3.2/topics/files/), I should be able to update the name of an uploaded file like so:
    22
    3 >>> import os
    4 >>> from django.conf import settings
    5 >>> initial_path = car.photo.path
    6 >>> car.photo.name = 'cars/chevy_ii.jpg'
    7 >>> new_path = settings.MEDIA_ROOT + car.photo.name
    8 >>> # Move the file on the filesystem
    9 >>> os.rename(initial_path, new_path)
    10 >>> car.save()
    11 >>> car.photo.path
     3{{{
     4import os
     5from django.conf import settings
     6initial_path = car.photo.path
     7car.photo.name = 'cars/chevy_ii.jpg'
     8new_path = settings.MEDIA_ROOT + car.photo.name
     9# Move the file on the filesystem
     10os.rename(initial_path, new_path)
     11car.save()
     12car.photo.path
    1213'/media/cars/chevy_ii.jpg'
    13 >>> car.photo.path == new_path
     14car.photo.path == new_path
    1415True
     16}}}
     17
    1518
    1619This does not work.
Back to Top