Skip to content

Instantly share code, notes, and snippets.

import requests
resp = requests.get('http://jsonplaceholder.typicode.com/albums/3/photos/')
no_of_albums = len(resp.json())
@bee-keeper
bee-keeper / Month year only in django dateField
Created August 20, 2014 11:27
Display only month, year in django admin and django list_display
#models.py
class SomeClass(models.Model):
date = models.DateField()
#forms.py
date = forms.DateField(widget=MonthYearWidget)
# Get widget here -> https://djangosnippets.org/snippets/1688/
#admin.py
class SomeClassAdmin(admin.ModelAdmin):
@bee-keeper
bee-keeper / Disable allauth registration
Created May 19, 2014 13:30
Disable allauth signup/registration
"""
Disable registration/signup
"""
#models.py
from allauth.account.adapter import DefaultAccountAdapter
class MyAccountAdapter(DefaultAccountAdapter):
def is_open_for_signup(self, request):
return False
@bee-keeper
bee-keeper / Django: Programmatically add permissions to groups
Created March 29, 2014 16:57
Django: Programmatically add permissions to groups
content_type = ContentType.objects.get(app_label='', model='')
#get all permssions for this model
perms = Permission.objects.filter(content_type=content_type)
group = Group.objects.get(name='')
for p in perms:
group.permissions.add(perms)
@bee-keeper
bee-keeper / Flatpage example fixture
Created March 18, 2014 09:29
Example fixture for flatpage and flatpage migration example
#instantiation example
from django.contrib.flatpages.models import FlatPage
flatpage = FlatPage.objects.create(id=, title=, template_name=, content=)
flatpage.sites.add(2)
#fixture example
[
{
"pk": 1,