Skip to content

Instantly share code, notes, and snippets.

@andybak
andybak / gist:944595
Created April 27, 2011 16:23
A Python style question
class MultipleChoiceAnswerForm(ModelForm):
class Meta:
model = MultipleChoiceAnswer
fields=('question' ,'answer',)
widgets = {
'question': HiddenInput(),
'answer': RadioSelect(renderer=MyRadioRenderer),
}
@andybak
andybak / django-1.2.5-lookup_allowed-example.py
Created May 16, 2011 09:39 — forked from acdha/django-1.2.5-lookup_allowed-example.py
How to whitelist other admin lookups with Django 1.2.5
class FooAdmin(ModelAdmin):
def lookup_allowed(self, key, value):
# NOTE: Django 1.2.5 changed the call signature to add the value
# Django 1.2.4 restricted the list of allowed lookups to only those
# specified in list_filter or date_hierarchy, which doesn't help when
# we need to filter on a list with thousands of options. We'll
# override that to allow the few which we actually use:
if key in ('related__pk', 'related__custom_field'):
return True
@andybak
andybak / mixins.py
Created July 15, 2011 06:58
Nav mixin
from django.core.urlresolvers import reverse
from django.contrib.admin import site
from django.template.loader import render_to_string
from django.utils.safestring import mark_safe
from cms.utils import get_page_from_url
class NavigableMixin(object):
"""
@andybak
andybak / gist:4023859
Created November 6, 2012 10:14
List of interesting Django dmin-related code and projects
https://github.com/exogen/django-adminbrowse
import os
DEBUG = True
TEMPLATE_DEBUG = True
LOCAL_DEV = True
OFFLINE = False
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
@andybak
andybak / a-rectangle-by-google
Last active December 24, 2015 07:59 — forked from ColemanGariety/a-rectangle-by-google
reformat the javascript
<!DOCTYPE html>
<html>
<head data-gwd-animation-mode="quickMode">
<title>Index</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="generator" content="Google Web Designer 1.0.0.924">
<style type="text/css">
html, body {
width: 100%;
var stockApp = angular.module('stockApp', [
'ngResource',
]);
stockApp.value('currentBooking', {bookingId: BOOKING_ID});
stockApp.factory('TimeBlock', [function() {
}]);
@andybak
andybak / booking.html
Created January 11, 2014 16:07
You have failed me for the final time, brain.
<div id='BookingCtrl' ng-controller="BookingCtrl">
<div id='StockListCtrl' ng-controller="StockListCtrl">
<h1>Status: {{ booking().status }} Chargeable days: {{ booking().chargeable_days }}</h1>
<section class="timeline-stock light clearfix">
<header class="timeline-header clearfix">
<div id="form-booking">
<div class="input-pair"><label for="hire-start">Est. Delivery</label><input name="hire-start" class="text lg" type="datetime-local" value="{{ booking().estimated_dispatch }}"></div>
<div class="input-pair"><label for="hire-end">Est. Collection</label><input name="hire-end" class="text lg" type="datetime-local" value="{{ booking().estimated_return }}"></div>
<button id="refresh-hire-period" class="button action lg"><i class="fa fa-refresh fa-lg"></i></button>
<div class="search-wrapper">
from django.core.management.base import BaseCommand, CommandError
from sorl.thumbnail import default
from shutil import rmtree
from os import listdir
class Command(BaseCommand):
help = (
u'Truncates kvstore and cleanup _thumbs_ folder'
)
<dd><input type="text" value="{{ getBooking().account.name }}"></dd>
Goes to
<dd><input type="text" ng-model="getBooking().account.name"></dd>