Skip to content

Instantly share code, notes, and snippets.

View mgrouchy's full-sized avatar

Mike Grouchy mgrouchy

View GitHub Profile
class Container(models.Model):
children = models.OneToManyField(Child) #I know this one to many field does not exist
class Child(models.Model):
random_field = models.IntegerField(default=1)
from django.auth.models import User
from django.shortcuts import get_object_or_404
#this view would be publicly accessable
def hook(request, username=None):
user = get_object_or_404(User, username=username) #cant remember the syntax
if not isinstance(User, user):
return user #this returns a 404
#now we know what user we are dealing with
from django.models import Model
from django.auth.models import User
class Achievement(Model):
user = models.foreignKey(User)
created_at = models.DateTimeField()
def fetch_achievement(self):
#do some achievement logic in here
@mgrouchy
mgrouchy / .bashrc
Created February 21, 2011 15:51 — forked from henrik/.bashrc
# http://henrik.nyh.se/2008/12/git-dirty-prompt
# http://www.simplisticcomplexity.com/2008/03/13/show-your-git-branch-name-in-your-prompt/
# username@Machine ~/dev/dir[master]$ # clean working directory
# username@Machine ~/dev/dir[master*]$ # dirty working directory
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
def override_urls(self):
return [
url(r'^offer/(?P<offer_id>\d+)/(?P<resource_name>%s)/(?P<offer_transaction_id>\d+)/$' % self._meta.resource_name, self.wrap_view('get_offer_transaction_id'), name="api_get_offer_transaction_id"),
url(r'^offer/(?P<offer_id>\d+)/(?P<resource_name>%s)/$' % self._meta.resource_name, self.wrap_view('get_offer_transaction'), name="api_get_offer_transaction"),
]
@mgrouchy
mgrouchy / funkypatterns.py
Created February 16, 2011 21:02
funky url patterns
patterns = [
(r'^(?P<resource_name>offer)/(?P<pk_list>\w[\w/;-]*)/$', someview),
(r'^offer/(?P<offer_id>\d+)/(?P<resource_name>transaction)/$', someotherview),
(r'^offer/(?P<offer_id>\d+)/(?P<resource_name>transaction)/(?P<offer_transaction_id>\d+)/$', someview),
]
" Vim syntax file
" Language: Django template
" Maintainer: Dave Hodder <dmh@dmh.org.uk>
" Last Change: 2010 May 19
" For version 5.x: Clear all syntax items
" For version 6.x: Quit when a syntax file was already loaded
if version < 600
syntax clear
elseif exists("b:current_syntax")
mkdir ~/virtualenvs
if settings.DEBUG:
urlpatterns += patterns("",
(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT, 'show_indexes':True}),)
#first generate a key for your domain
openssl genrsa -out yourdomain.com.key 2048
#then generate the request
openssl req -new -key yourdomain.com.key -out yourdomain.com.csr