Django - passing extra arguments into upload_to callable function

前端 未结 1 1576
我在风中等你
我在风中等你 2021-01-13 13:23

I know that you can use the upload_to parameter to pass a callable function to dynamically alter a FileFied/ImageField, etc. in a Django model.

The function called

相关标签:
1条回答
  • 2021-01-13 13:53

    The instance variable is the Badge() instance. You could access it's properties as usual

    def format_badge_name(instance, filename):
        instance.name
        instance.file
        ...
    

    You could name the instance 'self', and it might be easier to be understood:

    def format_badge_name(self, filename):
        self.name
        self.file
        ...
    
    0 讨论(0)
提交回复
热议问题