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
精彩评论