Skip to content

Instantly share code, notes, and snippets.

View Greymalkin's full-sized avatar

Patricia Lee Greymalkin

View GitHub Profile

Customize Save In Django Admin Inline Form

Background

This is a common case in django ORM.

from django.db import models

class Author(models.Model):
@Greymalkin
Greymalkin / forms.py
Created February 26, 2014 15:55 — forked from mattoc/forms.py
"""Allows checking of form POST data as well as uploaded files when validating
a standard Django `forms.Form`.
The short version is that you check `Form().files` in the `clean()` method,
assuming the form has been bound to the request.
See:
http://mattoc.com/django-handle-form-validation-with-combined-post-and-files-data/
"""
# -*- coding: utf-8 -*-
import Image
def resize_and_crop(img_path, modified_path, size, crop_type='top'):
"""
Resize and crop an image to fit the specified size.
args:
img_path: path for the image to resize.