[Solved]-Get application name in Django model

15👍

There is an attribute app_label in _meta attribute. Please see this stackoverflow question

3👍

from os import path

def _get_upload_to(instance, filename):
    return path.join(instance._meta.app_label, 'subdir', filename)

class MyModel(models.Model):
    ....
    datoteka = models.FileField(upload_to=_get_upload_to, ...)

Will result in ‘MyApp/subdir’ upload path.

👤MrKsn

Leave a comment