Created
December 27, 2016 12:31
-
-
Save dwickstrom/ec8fe7096f9ff9e9a5f753ef289e97c4 to your computer and use it in GitHub Desktop.
Get attribute settings off a model
This file contains hidden or 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
# 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