开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜