开发者

How do I define an ImageField in a Django abstract model?

开发者 https://www.devze.com 2022-12-16 22:27 出处:网络
I have an abstract Django model and I want to define an ImageField inside of it. The problem is that when I do define it, it raises an error because I don\'开发者_如何学编程t have an \"upload_to\" att

I have an abstract Django model and I want to define an ImageField inside of it. The problem is that when I do define it, it raises an error because I don'开发者_如何学编程t have an "upload_to" attribute. Is there a way to still define it and have a separate folder for each inheriting class?


upload_to can be a callable.

image=models.ImageField(upload_to=my_callable)

where callable is something like this:

def my_callable(instance,filename):
    path='sth depending on class name'
    return path
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号