Django: Access primary key in models.filefield(upload_to) location

前端 未结 4 1454
一生所求
一生所求 2020-12-16 16:51

I\'d like to save my files using the primary key of the entry.

Here is my code:

def get_nzb_filename(instance, filename):
    if not instance.pk:
            


        
4条回答
  •  眼角桃花
    2020-12-16 17:27

    Ty, is there a reason you rolled your own slugify filter?

    Django ships with a built-in slugify filter, you can use it like so:

    from django.template.defaultfilters import slugify
    
    slug = slugify(some_string)
    

    Not sure if you were aware it was available to use...

提交回复
热议问题