From d753a7f33368073eabbe11de1cf93bf0f8830d75 Mon Sep 17 00:00:00 2001 From: Jacob Foster Date: Sat, 14 Oct 2017 14:50:35 -0500 Subject: [PATCH] Make INCLUDE_FOREIGNKEY_IDS a global option --- graphene_django/settings.py | 2 ++ graphene_django/types.py | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/graphene_django/settings.py b/graphene_django/settings.py index 46d70ee..c3301cd 100644 --- a/graphene_django/settings.py +++ b/graphene_django/settings.py @@ -35,6 +35,8 @@ DEFAULTS = { 'RELAY_CONNECTION_ENFORCE_FIRST_OR_LAST': False, # Max items returned in ConnectionFields / FilterConnectionFields 'RELAY_CONNECTION_MAX_LIMIT': 100, + # Set to True if you want all models to include ForeignKey id fields + 'INCLUDE_FOREIGNKEY_IDS': False } if settings.DEBUG: diff --git a/graphene_django/types.py b/graphene_django/types.py index de8abd4..be2a892 100644 --- a/graphene_django/types.py +++ b/graphene_django/types.py @@ -9,6 +9,7 @@ from graphene.types.utils import yank_fields_from_attrs from .converter import convert_django_field_with_choices, convert_field_to_id from .registry import Registry, get_global_registry +from .settings import graphene_settings from .utils import (DJANGO_FILTER_INSTALLED, get_model_fields, is_valid_django_model) @@ -34,7 +35,7 @@ def construct_fields(model, registry, only_fields, exclude_fields): attname = getattr(field, 'attname', '') add_foreignkey_attname = all([ isinstance(field, ForeignKey), - options.include_foreignkey_ids, + graphene_settings.INCLUDE_FOREIGNKEY_IDS, attname not in fields, ]) if add_foreignkey_attname: