Skip to content

Instantly share code, notes, and snippets.

View rluts's full-sized avatar

rluts rluts

  • Ukraine
View GitHub Profile
from django.db import models
from django.conf import settings
import pkgutil
import os
from importlib import import_module
from functools import partialmethod
class PluginField(models.CharField):
"""
@rluts
rluts / imagewiththumbnails_updateable.py
Last active May 18, 2018 18:29 — forked from valberg/imagewiththumbnails_updateable.py
Django create thumbnail form ImageField and save in a different ImageField - now with updating!
def create_thumbnail(instance, image_field, thumb_field):
# original code for this method came from
# http://snipt.net/danfreak/generate-thumbnails-in-django-with-pil/
# https://gist.github.com/valberg/2429288
# adapted to python 3
# insert this code to utils.py
@rluts
rluts / token_auth.py
Last active October 13, 2023 20:56
Token authorization middleware for Django Channels 2
from channels.auth import AuthMiddlewareStack
from rest_framework.authtoken.models import Token
from django.contrib.auth.models import AnonymousUser
from django.db import close_old_connections
class TokenAuthMiddleware:
"""
Token authorization middleware for Django Channels 2
"""