Skip to content

Instantly share code, notes, and snippets.

View tochimclaren's full-sized avatar
🏠
Working from home

tochimclaren tochimclaren

🏠
Working from home
View GitHub Profile
@pgrangeiro
pgrangeiro / celery.py
Last active March 26, 2023 22:27
Django Celery Beat Example
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
from django.conf import settings
from robot.config import ROBOT_CELERY_BEAT_SCHEDULE
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'test.settings')
@josephabrahams
josephabrahams / admin.py
Created May 31, 2015 17:55
Limit number of Django model instances
from django.contrib import admin
from example.models import Example
class ExampleAdmin(admin.ModelAdmin):
"""
Don't allow addition of more than one model instance in Django admin
See: http://stackoverflow.com/a/12469482
"""
def has_add_permission(self, request):
@andkon
andkon / Install instructions
Created March 14, 2015 18:12
Installing celery on django and heroku
pip install celery
heroku addons:add cloudamqp
heroku config | grep CLOUDAMQP_URL
^^ that is the URL to put in celeryconfig
@magopian
magopian / admin_list_editable_autosubmit.js
Last active September 10, 2021 15:51
Small js script that automatically submits the changelist form on field changes. This is convenient when used with https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_editable, and avoids having to remember to submit the form when done (the form on the changelist page doesn't look like a form after all, …
/*
* Only useful in changelist pages when the ModelAdmin displayed has
* "list_editable" (https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_editable)
* configured.
*
* When one of the input/select/textarea value is changed, automatically submit
* the form using ajax.
*
* Only form fields relevant to the "list_editable" will trigger a form submit.
*
@kvnn
kvnn / DJANGO_get_next_or_prev
Created April 4, 2012 16:33
Django: Get next or previous item of a Queryset
''' Useage ''''
# Declare our item
store = Store.objects.get(pk=pk)
# Define our models
stores = Store.objects.all()
# Ask for the next item
new_store = get_next_or_prev(stores, store, 'next')
# If there is a next item
if new_store:
# Replace our item with the next one
@jaydson
jaydson / gist:1780598
Created February 9, 2012 15:11
How to detect a click event on a cross domain iframe
var myConfObj = {
iframeMouseOver : false
}
window.addEventListener('blur',function(){
if(myConfObj.iframeMouseOver){
console.log('Wow! Iframe Click!');
}
});
document.getElementById('YOUR_CONTAINER_ID').addEventListener('mouseover',function(){
@ChrisLTD
ChrisLTD / gist:957014
Created May 5, 2011 13:28
Django Nested Regroup Example (Group by category foreign key, then month of start date)
#views.py
def events_index(request, year):
selected_year = Year.objects.get(title=year)
events_list = Event.objects.filter(year = selected_year.id).order_by('category','start_date')
return render_to_response('events_list.html', {"events_list": events_list})
#events_list.html
{% regroup events_list by category.title as events_list_by_category %}