Skip to content

Instantly share code, notes, and snippets.

View webjunkie's full-sized avatar

Julian Bez webjunkie

View GitHub Profile
@webjunkie
webjunkie / swagger2django.py
Created February 2, 2016 13:34
Convert swagger to django model definition
import json
with open("swagger.json", "r") as f:
data = json.load(f)
def print_properties(value, pad=""):
properties = value.get('properties', {})
required = value.get('required', [])
@webjunkie
webjunkie / forms.py
Last active February 4, 2023 22:12
JSONFieldFormMixin for Django ModelForm with JSON field
# the mixin
class JSONFieldFormMixin(object):
"""
Given that a model has some kind of TextField ``json_storage_field`` with
a string of JSON formatted data inside, this mixin adds handling of this
field to a ModelForm.
It will read the text field, convert to Python dict, fill the form fields
that are given via ``json_fields`` and on saving will write this back to
@webjunkie
webjunkie / fields.py
Last active September 2, 2016 10:45
MultipleChoiceCommaField for Django reads and saves comma separated values
from django import forms
from django.core.exceptions import ValidationError
class MultipleChoiceCommaField(forms.MultipleChoiceField):
"""
Store a comma separated list of multiple choice values in a CharField/TextField
"""
widget = forms.CheckboxSelectMultiple
@webjunkie
webjunkie / keybase.md
Created April 8, 2019 13:39
keybase.md

Keybase proof

I hereby claim:

  • I am webjunkie on github.
  • I am webjunkie (https://keybase.io/webjunkie) on keybase.
  • I have a public key ASBtMhNKBhfhgDgYl9Z5i61wA9tsNrhd5Udlatwnz_jEVwo

To claim this, I am signing this object: