2012-04-02 64 views
0

我想爲django管理站點中的圖像裁剪添加一個功能。我不知道如何解決這個問題。我已經使用了django-image-cropping應用程序,但無法將其集成到管理端。如何在django管理端裁剪圖像?

+0

相關:http://stackoverflow.com/questions/7907803/django-app-for-image-crop-using-a-cropping - 工具。 – 2012-04-02 10:56:54

+0

經歷過這個但沒有想法在django管理員端實現。 – PythonDev 2012-04-02 11:04:46

+3

您需要回頭接受以前的8個問題的答案 – 2012-04-02 11:26:00

回答

2

你應該定義保存在您的模型()方法:

class MyImage(models.Model): 
    image = models.ImageField(...) 
    image_crop = models.ImageField(blank=True) 

    def save(): 
    super(MyImage, self).save() #will save only image, image_corp will be blank. 

    image_path = self.image.path #path to your non croped image 

    #now you can load image file and crop it usung PIL and save. 

    self.image_crop = 'path/to/cropped/image' #add path to cropped image. 
    super(MyImage, self).save() #save data.