id,summary,reporter,owner,description,type,status,component,version,severity,resolution,keywords,cc,stage,has_patch,needs_docs,needs_tests,needs_better_patch,easy,ui_ux 33944,Is it cleaner to make the upload_to function a method of the model class,Willem Van Onsem,nobody,"In the documentation of the `upload_to` field (https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.FileField.upload_to), it works with an example: {{{ def user_directory_path(instance, filename): # file will be uploaded to MEDIA_ROOT/user_/ return 'user_{0}/{1}'.format(instance.user.id, filename) class MyModel(models.Model): upload = models.FileField(upload_to=user_directory_path) }}} I'm wondering if this isn't more convenient by defining this as an instance method, so: {{{ class MyModel(models.Model): def user_directory_path(self, filename): # file will be uploaded to MEDIA_ROOT/user_/ return 'user_{0}/{1}'.format(self.user.id, filename) upload = models.FileField(upload_to=user_directory_path) }}} Then the function can be used as a method, for example to just determine a file path without having to use it in the `FileField` per se. It also avoid defining all ""standalone"" functions that seem to be coupled to a model, and thus will make the `models.py` file less chaotic.",New feature,closed,Documentation,dev,Normal,invalid,,,Unreviewed,0,0,0,0,0,0