Djangoではモデルを使用します
class Specialist(models.Model):
...
photo = models.ImageField(_('photo'), upload_to='spec_foto')
...
新しいオブジェクトを作成して保存すると、「写真」フィールドが .../spec_photo/filename.jpg になりますが、ファイルを .../spec_photo/ID/photo.jpg に移動したいと思います。 Specialist オブジェクトに属します。そのために、Model.save メソッドをオーバーライドします。
def save(self):
# Saving a new object and getting ID
super(Specialist, self).save()
# After getting ID, move photo file to the right destination
# ????
# Saving the object with the right file destination
super(Specialist, self).save()
問題は、ファイルを移動するにはどうすればよいですか? (??? コード内)。それとももっと簡単な方法がありますか?