Django ImageField change file name on upload

前端 未结 5 1566
没有蜡笔的小新
没有蜡笔的小新 2021-01-30 04:35

Upon saving me model \'Products\' I would like the uploaded image to be named the same as the pk for example 22.png or 34.gif I don\'t want to change the format of the image jus

5条回答
  •  闹比i
    闹比i (楼主)
    2021-01-30 04:50

    You can replace the string your assigning to upload_to with a callable as described in the docs. However, I suspect the primary key may not be available at the point the upload_to parameter is used.

提交回复
热议问题