- Initial ASGI support is confirmed as landing in 3.0 - I think a fully async story won't land (and that will include docs for it all) until 3.2 (LTS)
- WSGI support will get dropped at 4.2, presuming that's the next LTS after 3.2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for frame in inspect.getouterframes(inspect.currentframe()): | |
| if frame.function.startswith("test_"): | |
| repr = "<unknown>" | |
| caller = "" | |
| if "self" in frame.frame.f_locals: | |
| caller = frame.frame.f_locals["self"] | |
| elif "cls" in frame.frame.f_locals: | |
| caller = frame.frame.f_locals["cls"] | |
| if caller: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| import threading | |
| from operator import itemgetter | |
| from pprint import pprint, saferepr | |
| keyonly = itemgetter(0) | |
| class ZMixin: | |
| def mixin_via_z(self) -> int: | |
| varz = 999 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class F(forms.Form): | |
| def to_querydict(self): | |
| if not self.is_bound or not hasattr(self, 'cleaned_data'): | |
| return QueryDict('') | |
| qd = QueryDict('', mutable=True) | |
| get_or_default = self.data.get | |
| if isinstance(self.data, QueryDict): | |
| get_or_default = self.data.getlist | |
| for key, value in self.cleaned_data.items(): | |
| prefixed_key = self.add_prefix(key) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Given this doesn't work | |
| qs = Song.objects | |
| qs = qs.prefetch_related( | |
| db.models.Prefetch( | |
| "releases", queryset=SongRelease.objects.raw( | |
| """ | |
| SELECT id, target FROM tungsten_song_release; | |
| """ | |
| ), | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.db.models import Q | |
| from functools import reduce | |
| from operator import or_ | |
| values = ( | |
| ('myfield__iexact', 1), | |
| ('myotherfield__iexact', 2), | |
| ('myfield__iexact', 3), | |
| ('mythirdfield__icontains', 'test'), | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >>> class TestModel(models.Model): | |
| ... test_field = models.CharField(blank=True, null=True) | |
| ... class Meta: | |
| ... app_label="test" | |
| >>> TestModel.objects.exclude(test_field='').query.__str__() | |
| 'SELECT "test_testmodel"."id", "test_testmodel"."test_field" FROM "test_testmodel" WHERE NOT ("test_testmodel"."test_field" = AND "test_testmodel"."test_field" IS NOT NULL)' | |
| >>> import django | |
| >>> django.VERSION | |
| (2, 2, 4, 'final', 0) | |
| >>> from django.conf import settings |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >>> import os | |
| >>> os.environ['DJANGO_SETTINGS_MODULE'] = '' | |
| >>> from django.conf import settings | |
| >>> settings.configure(TIME_ZONE='UTC') | |
| >>> os.environ['TZ'] | |
| KeyError... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class TempTabler(object): | |
| __slots__ = ("queryset", "model", "name", "create_template", "drop_template") | |
| def __init__(self, query, model, name): | |
| # type: (QuerySet, Type[Model], str) -> None | |
| self.queryset = query | |
| class TempTable(model): | |
| class Meta(model.Meta): | |
| abstract = False | |
| managed = False | |
| db_table = name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /Users/kez | |
| /Users/kez/.pyenv | |
| /Users/kez/.pyenv/versions | |
| /Users/kez/.pyenv/versions/3.6.2 | |
| /Users/kez/.pyenv/versions/3.6.2/lib | |
| /Users/kez/.pyenv/versions/3.6.2/lib/python3.6 | |
| /Users/kez/.pyenv/versions/3.6.2/lib/python3.6/asyncio | |
| /Users/kez/.pyenv/versions/3.6.2/lib/python3.6/asyncio/selector_events.py | |
| /Users | |
| Traceback (most recent call last): |
NewerOlder