Skip to content

Instantly share code, notes, and snippets.

Lars van de Kerkhof specialunderwear

Block or report user

Report or block specialunderwear

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View 0002_though.py
# Generated by Django 2.2 on 2019-04-22 12:38
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('through', '0001_initial'),
]
@specialunderwear
specialunderwear / metainnerclass.py
Last active Jul 12, 2019
Have a Meta inner class like in django, that will turn into a _meta attribute.
View metainnerclass.py
from django.utils.functional import cached_property
class MetaClass(object):
def __init__(self, attrs, endpointname):
self.__dict__.update(attrs)
self.endpointname = endpointname
@cached_property
def endpoint(self):
View fake_autocreated.py
from contextlib import contextmanager
from unittest.mock import patch
@contextmanager
def fake_autocreated(many_to_many_manager):
"Do not give a shit about any intermediate models, just update the relation"
with patch.object(many_to_many_manager.through._meta, "auto_created", True):
yield many_to_many_manager
View populate_dashboard_emails.py
from copy import deepcopy
from unittest import mock
from django.conf import settings
from django.core.management.base import BaseCommand
from django.utils.translation import override
from django.template import base as template
from django.template import defaulttags
from oscar.core.loading import get_model
View inspectdb.py
from django.db import models
class ThroughFooBars(models.Model):
foo = models.ForeignKey('ThroughFoo', models.DO_NOTHING)
bar = models.ForeignKey('ThroughBar', models.DO_NOTHING)
order = models.PositiveIntegerField()
class Meta:
managed = False
View 0002_through.py
# Generated by Django 2.2 on 2019-04-22 11:25
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('through', '0001_initial'),
]
View models.py
from django.db import models
class Bar(models.Model):
spam = models.EmailField()
class Foo(models.Model):
bars = models.ManyToManyField(Bar, through='ThroughFooBars')
@specialunderwear
specialunderwear / initialize.py
Created May 11, 2017
Initialize a package directory structure with __init__.py files.
View initialize.py
#! /usr/bin/env python
import os
import argparse
def visit(arg, dirname, names):
name = os.path.join(arg, dirname, '__init__.py')
if not os.path.exists(name):
open(name, 'a').close()
@specialunderwear
specialunderwear / ▼spyne■delegate.py
Last active Dec 2, 2016
Spyne services with inheritance.
View ▼spyne■delegate.py
import inspect
from functools import partial, update_wrapper
from spyne.decorator import rpc as original_rpc
from spyne.service import ServiceBase, ServiceBaseMeta
__all__ = ('rpc', 'DelegateBase', 'ExtensibleServiceBase')
class SpyneMethodWrapper(object):
"""
View uwsgi.conf
[uwsgi]
master = true
workers = 1
reload-mercy = 30
vacuum = 1
socket = my.sock
auto-procname = true
enable-threads = true
lazy = 0
plugin = python
You can’t perform that action at this time.