Вы должны использовать тригонометрию, чтобы определить правильную ширину / высоту, используя прозрачность, чтобы предотвратить черную область, и я думаю, что Трансформация неверна, что делает ее недоступной.
Попробуйте следующее:
public static BufferedImage rotate(BufferedImage image, double angle) {
double sin = Math.abs(Math.sin(angle)), cos = Math.abs(Math.cos(angle));
int w = image.getWidth(), h = image.getHeight();
int neww = (int)Math.floor(w*cos+h*sin), newh = (int) Math.floor(h * cos + w * sin);
GraphicsConfiguration gc = getDefaultConfiguration();
BufferedImage result = gc.createCompatibleImage(neww, newh, Transparency.TRANSLUCENT);
Graphics2D g = result.createGraphics();
g.translate((neww - w) / 2, (newh - h) / 2);
g.rotate(angle, w / 2, h / 2);
g.drawRenderedImage(image, null);
g.dispose();
return result;
}
private static GraphicsConfiguration getDefaultConfiguration() {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
return gd.getDefaultConfiguration();
}
из http://flyingdogz.wordpress.com/2008/02/11/image-rotate-in-java-2-easier-to-use/
Вы можете использовать аннотацию Exists
.
from django.db.models import OuterRef, Exists
class NewModelAdmin(admin.ModelAdmin):
def get_queryset(self, request):
queryset = super(NewModelAdmin, self).get_queryset(request)
old_model = OldModel.objects.filter(old_path=OuterRef('url'))
return queryset.annotate(
has_old_model=Exists(old_model),
)
class NewModel(models.Model):
...
@property
def is_redirected(self):
if hasattr(self, 'has_old_model'):
return self.has_old_model
# Fall back to previous method if you're worried
# you don't have all paths covered.
return OtherModel.objects.filter(old_path=self.url).exists()