Make Tastypie Respect blank=False

More Tastypie pain, documented in several issues. Tastypie’s blank attribute simply doesn’t work. Add this to your Resource as a workaround:

class MyResource(ModelResource):
    # Workaround for this issue:
    # https://github.com/toastdriven/django-tastypie/issues/518
    def hydrate(self, bundle):
        for field_name, field_obj in self.fields.items():
            if field_name == 'resource_uri':
                continue
            if not field_obj.blank and not bundle.data.has_key(field_name):
                raise ApiFieldError("The '%s' field has no data and doesn't allow a default or null value." % field_name)
        return bundle