Skip to content

Instantly share code, notes, and snippets.

View zarinpy's full-sized avatar
💭
I may be slow to respond.

omid Zarinmahd Ziaabadi zarinpy

💭
I may be slow to respond.
View GitHub Profile
@jaysonrowe
jaysonrowe / gmail_test.py
Created November 12, 2012 03:15
Checking Gmail with Selenium Webdriver in Python
#! /usr/bin/env python
import unittest
from selenium import webdriver
class TestGmail(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
@JSONOrona
JSONOrona / parser.py
Last active January 4, 2021 16:37
Python command line argument example using argparse module
#!/usr/bin/python
''' Python command line argument example using argparse module
Example output:
./parser.py --server=pyserver --port=8080,443,25,22,21 --keyword=pyisgood
Server name: [ pyserver ]
@jrnk
jrnk / ISO-639-1-language.json
Last active November 8, 2024 16:53
ISO 639-1 Alpha-2 codes of languages JSON
[
{ "code": "aa", "name": "Afar" },
{ "code": "ab", "name": "Abkhazian" },
{ "code": "ae", "name": "Avestan" },
{ "code": "af", "name": "Afrikaans" },
{ "code": "ak", "name": "Akan" },
{ "code": "am", "name": "Amharic" },
{ "code": "an", "name": "Aragonese" },
{ "code": "ar", "name": "Arabic" },
{ "code": "as", "name": "Assamese" },
@Guest007
Guest007 / admin.py
Created December 16, 2016 11:43
JSON editor in admin for Django, jsoneditor, Postgres (from http://stackoverflow.com/a/40326235/2742038)
from django import forms
from django.contrib import admin
from django.utils.safestring import mark_safe
from django.template.loader import render_to_string
from .models import Consumer
class JSONEditorWidget(forms.Widget):

Serializer and Permission per action in Django REST Framework

In Django REST Framework you have a Viewsets, which can contain multiple views (actions). But to use different serializers and permissions for each action you always need to override get_serializer_class or get_permissions methods. Here I've implemented a mixins which allow you to setup your serializers and permissions per action in a dictionaries

Usage Example

class UserViewSet(SerializerPerAction, PermissionPerAction, ModelViewSet):
    queryset = User.objects.all()
    action_serializers = {