This is a common case in django ORM.
from django.db import models
class Author(models.Model):
# in models.py | |
from django.contrib.contenttypes.fields import GenericForeignKey | |
from django.contrib.contenttypes.models import ContentType | |
from django.db import models | |
class Screen(models.Model): | |
# Screen Model: Ties into all shows, drives instance selection when using generic foreign keys | |
name = models.CharField(max_length=50) | |
limit = (models.Q( | |
models.Q(app_label='case_story', model='casestoryshow') | |
# in requirements.txt | |
django-request-provider==1.0.2 | |
# in settings.py | |
MIDDLEWARE_CLASSES += ['request_provider.middleware.RequestProvider',] | |
# in admin.py | |
from request_provider.signals import get_request | |
class MeetAdmin(admin.ModelAdmin): |
from django.db.models import Count | |
from django.db.models.sql.where import ExtraWhere, AND | |
from django.db import reset_queries, connection | |
>>> categories = '27,18' | |
>>> filter_string = 'ringtones_bundle_category.category_id IN ({})'.format(categories) | |
>>> bundle_join_string = 'ringtones_bundlepack.bundle_id = ringtones_bundle.id' | |
>>> category_join_string = 'ringtones_bundle_category.bundle_id = ringtones_bundle.id' | |
>>> models.BundlePack.objects.extra(where=[string,'ringtones_bundle_category.bundle_id = ringtones_bundle.id','ringtones_bundlepack.bundle_id = ringtones_bundle.id']).extra(tables=['ringtones_bundle_category','ringtones_bundle']).distinct() |
brew install rename | |
==> Downloading https://github.com/ap/rename | |
rename 'y/A-Z/a-z/' * -f |
# http://stackoverflow.com/questions/11637293/iterate-over-object-attributes-in-python | |
def __init__(self, *args, **kwargs): | |
print('***** init') | |
for a in args: | |
print(a) | |
for k in kwargs: | |
print (k) | |
print([a for a in dir(self) if not a.startswith('__')]) | |
print self.formset | |
print([a for a in dir(self.formset) if not a.startswith('__')]) |
"""Allows checking of form POST data as well as uploaded files when validating | |
a standard Django `forms.Form`. | |
The short version is that you check `Form().files` in the `clean()` method, | |
assuming the form has been bound to the request. | |
See: | |
http://mattoc.com/django-handle-form-validation-with-combined-post-and-files-data/ | |
""" |
# -*- coding: utf-8 -*- | |
import Image | |
def resize_and_crop(img_path, modified_path, size, crop_type='top'): | |
""" | |
Resize and crop an image to fit the specified size. | |
args: | |
img_path: path for the image to resize. |
variables.framework = {}; | |
variables.framework.defaultSection = 'main'; | |
variables.framework.defaultItem = 'main'; | |
variables.framework.reloadApplicationOnEveryRequest = true; | |
variables.framework.suppressImplicitService = true; |