Skip to content

Instantly share code, notes, and snippets.

View sanbartels's full-sized avatar

Daniel Santiago Bartels Barragan sanbartels

View GitHub Profile
@sanbartels
sanbartels / workflows-in-django.md
Created March 13, 2017 19:20 — forked from Nagyman/workflows-in-django.md
Workflows in Django

Workflows (States) in Django

I'm going to cover a simple, but effective, utility for managing state and transitions (aka workflow). We often need to store the state (status) of a model and it should only be in one state at a time.

Common Software Uses

  • Publishing (Draft->Approved->Published->Expired->Deleted)
@sanbartels
sanbartels / admin.py
Created October 13, 2016 21:08 — forked from josephabrahams/admin.py
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):