Skip to content

Instantly share code, notes, and snippets.

##### yabl/settings.py
ROOT_URLCONF = 'yabl.urls'
TEMPLATE_DIRS = (
"/Users/jacob/training/yabl/templates",
)
##### yabl/urls.py
###### yabl/urls.py
from django.conf.urls.defaults import *
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^authors/', include('yabl.authors.urls')),
##### yabl/entries/models.py
import datetime
from django.db import models
from yabl.authors.models import Author
class EntryManager(models.Manager):
def future(self):
return self.filter(pub_date__gt=datetime.datetime.now())
##### yabl/entries/templatetags/entry_tags.py
from django import template
from yabl.entries.models import Entry
register = template.Library()
@register.inclusion_tag('entries/latest_snippet.html')
def latest_entries(num):
return {
##### yabl/urls.py
from django.conf.urls.defaults import *
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^authors/', include('yabl.authors.urls')),
import operator
from django.db.models import Q
def search(model_or_qs, search_fields, search_string):
"""
Perform a quick and dirty model "search", similar to how the admin's
`search_fields` works (see http://tinyurl.com/66xz2n)::
>>> search(Entry, ['summary', 'body'], 'content')
[...]
@jacobian
jacobian / gist:336445
Created March 18, 2010 15:06
Installing GeoDjango deps on Ubuntu 9.10
### Install some packages. Ignore the errors.
aptitude install binutils libgdal1-1.5.0 postgresql-8.3-postgis postgresql-server-dev-8.3 python-psycopg2 python-setuptools
### Make connecting to postgres easier
echo "local all all trust" > /etc/postgresql/8.3/main/pg_hba.conf
invoke-rc.d postgresql-8.3 reload
### Become the Postgres user to create a spatial template database:
# Poll interval of 2 minutes
set daemon 120
set logfile /var/log/monit.log
set mail-format {
from: [email protected]
subject: [monit] $SERVICE - $EVENT
}
# Global notify list
def tabletest(table):
def decorator(func):
def _inner():
for args in table:
yield tuple([func] + list(args))
_inner.__name__ = 'test_'+func.__name__
return _inner
return decorator
table = [(1, 2), (3, 4)]
>>> from django.contrib.auth.models import User
>>> import datetime
>>> User.objects.filter(date_joined__lte=datetime.datetime.now)
[<User: jacob>]