This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
resp = requests.get('http://jsonplaceholder.typicode.com/albums/3/photos/') | |
no_of_albums = len(resp.json()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Disable registration/signup | |
""" | |
#models.py | |
from allauth.account.adapter import DefaultAccountAdapter | |
class MyAccountAdapter(DefaultAccountAdapter): | |
def is_open_for_signup(self, request): | |
return False | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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, |