How to use the djangoql.schema.RelationField function in djangoql

To help you get started, we’ve selected a few djangoql examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ivelum / djangoql / djangoql / schema.py View on Github external
def get_field_instance(self, model, field_name):
        field = model._meta.get_field(field_name)
        field_kwargs = {'model': model, 'name': field.name}
        if field.is_relation:
            if not field.related_model:
                # GenericForeignKey
                return
            if self.excluded(field.related_model):
                return
            field_cls = RelationField
            field_kwargs['related_model'] = field.related_model
        else:
            field_cls = self.get_field_cls(field)
        if isinstance(field, (ManyToOneRel, ManyToManyRel, ForeignObjectRel)):
            # Django 1.8 doesn't have .null attribute for these fields
            field_kwargs['nullable'] = True
        else:
            field_kwargs['nullable'] = field.null
        field_kwargs['suggest_options'] = (
            field.name in self.suggest_options.get(model, [])
        )
        field_instance = field_cls(**field_kwargs)
        # Check if suggested options conflict with field type
        if field_cls != StrField and field_instance.suggest_options:
            for option in field_instance.get_options():
                if isinstance(option, text_type):
github ivelum / djangoql / djangoql / schema.py View on Github external
closed_set = list(exclude)

        while open_set:
            model = open_set.popleft()
            model_label = self.model_label(model)

            if model_label in closed_set:
                continue

            model_fields = OrderedDict()
            for field in self.get_fields(model):
                if not isinstance(field, DjangoQLField):
                    field = self.get_field_instance(model, field)
                if not field:
                    continue
                if isinstance(field, RelationField):
                    if field.relation not in closed_set:
                        model_fields[field.name] = field
                        open_set.append(field.related_model)
                else:
                    model_fields[field.name] = field

            result[model_label] = model_fields
            closed_set.append(model_label)

        return result
github ivelum / djangoql / djangoql / schema.py View on Github external
def __init__(self, model, name, related_model, nullable=False,
                 suggest_options=False):
        super(RelationField, self).__init__(
            model=model,
            name=name,
            nullable=nullable,
            suggest_options=suggest_options,
        )
        self.related_model = related_model
github ivelum / djangoql / djangoql / schema.py View on Github external
return
            if self.excluded(field.related_model):
                return
            field_cls = RelationField
            field_kwargs['related_model'] = field.related_model
        else:
            field_cls = self.get_field_cls(field)
        if isinstance(field, (ManyToOneRel, ManyToManyRel, ForeignObjectRel)):
            # Django 1.8 doesn't have .null attribute for these fields
            field_kwargs['nullable'] = True
        else:
            field_kwargs['nullable'] = field.null
        field_kwargs['suggest_options'] = (
            field.name in self.suggest_options.get(model, [])
        )
        field_instance = field_cls(**field_kwargs)
        # Check if suggested options conflict with field type
        if field_cls != StrField and field_instance.suggest_options:
            for option in field_instance.get_options():
                if isinstance(option, text_type):
                    # Convert to StrField
                    field_instance = StrField(**field_kwargs)
        return field_instance