Skip to content

Instantly share code, notes, and snippets.

@dwickstrom
Created December 27, 2016 12:31
Show Gist options
  • Save dwickstrom/ec8fe7096f9ff9e9a5f753ef289e97c4 to your computer and use it in GitHub Desktop.
Save dwickstrom/ec8fe7096f9ff9e9a5f753ef289e97c4 to your computer and use it in GitHub Desktop.
Get attribute settings off a model
# get_fields :: Model -> [Field]
def get_fields(model):
return model._meta.get_fields()
# get_field :: String -> Model -> Field
@curry
def get_field(name, model):
return model._meta.get_field(name)
# is_required :: String -> Model -> Boolean
@curry
def is_required(name, model):
return get_field(name, model).null is False
# is_optional :: String -> Model -> Boolean
@curry
def is_optional(name, model):
return not is_required(name, model)
[...]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment