Skip to content

Instantly share code, notes, and snippets.

@simonwoerpel
simonwoerpel / enum.py
Last active July 28, 2023 14:15
python enum member with name "name" doesn't appear in __dict__
from enum import Enum
e = Enum("MyEnum", ["name", "name2", "name3"])
# expected behaviour:
assert type(e.name) == type(e.name2) == type(e.name3) == e
assert e.name.value == 1
assert e.name2.value == 2
assert e.name3.value == 3

Keybase proof

I hereby claim:

  • I am simonwoerpel on github.
  • I am simonwoerpel (https://keybase.io/simonwoerpel) on keybase.
  • I have a public key ASDWJ9OdauOQzUm_FGJ2ibH6sI7-6Eit9OpLoSiT-Py5Fgo

To claim this, I am signing this object:

@simonwoerpel
simonwoerpel / mixin.py
Created August 25, 2015 22:58
django CachedPropertyCBVMixin
from django.utils.functional import cached_property
class CachedPropertyCBVMixin(object):
"""
ovverides self.get_object() and self.get_queryset()
with cached properties to reduce amount of executed querysets
"""
@cached_property
@simonwoerpel
simonwoerpel / obj_urlize.py
Last active August 29, 2015 14:16
Simple template filter for django to urlize objects,so you could use just{{ object|obj_urlize }}instead of<a href="{{ object.get_absolute_url }}">{{ object }}</a>where object is an instance of a django-modelor other class that has a get_absolute_url() -methodand __unicode__() defined.include this snippet somewhere into your templatetagsand make …
# coding=utf-8
__author__ = 'Simon Wörpel @simonwoerpel simon.woerpel@medienrevolte.de'
'''
Simple template filter for django to urlize objects,
so you could use just
{{ object|obj_urlize }}