Login

FileField having auto upload_to path

Author:
junaidmgithub
Posted:
May 20, 2022
Language:
Python
Version:
3.2
Score:
0 (after 0 ratings)

FileField having auto upload_to path

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
class FileField(models.FileField):
    def __init__(self, *args, **kwargs):
        assert not "upload_to" in kwargs
        kwargs["upload_to"] = self.get_upload_path
        super(FileField, self).__init__(*args, **kwargs)
    def get_upload_path(self, instance, filename):
        return os.path.join("_".join([
            instance._meta.app_label,
            instance._meta.object_name,
            self.name]), filename).lower()

More like this

  1. Month / Year SelectDateWidget based on django SelectDateWidget by pierreben 2 months, 4 weeks ago
  2. Python Django CRUD Example Tutorial by tuts_station 3 months, 2 weeks ago
  3. Browser-native date input field by kytta 4 months, 4 weeks ago
  4. Generate and render HTML Table by LLyaudet 5 months, 1 week ago
  5. My firs Snippets by GutemaG 5 months, 1 week ago

Comments

Please login first before commenting.