question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Django Model charField with choices : query field

See original GitHub issue

I have some problems when I try to query a Django charField with choices.

I have the following models.py :

class Vehicle(models.Model):
    TYPE_CHOICES = (
        ('MOTO', _('MOTORBIKE')),
        ('CAR', _('car')),
        ('BIKE', _('bike')),
    )

    name = models.CharField(max_length=100)

    vtype = models.CharField(
        _('Vehicle type'),
        max_length=5,
        choices=TYPE_CHOICES,
        default='MOTO',
        help_text=_('Lorem ipsum')
    )

    description = models.TextField(blank=True, default='')

    def __str__(self):
        return self.name

and the following schema.py :

  class VehicleNode(DjangoNode):
      class Meta:
          model = Vehicle

When I try to make this query :

query {
  allVehicles {
    edges {
      node {
        id,
        name,
        vtype
      }
    }
  }
}

I have the following error :

{
  "errors": [
    {
      "message": "Cannot query field \"vtype\" on type \"VehicleNode\".",
      "locations": [
        {
          "line": 7,
          "column": 9
        }
      ]
    }
  ]
}

To be able to query vtype I need to add vtype = String() into my schema like that :

class VehicleNode(DjangoNode):
    vtype  = String()
    class Meta:
        model = Vehicle

I don’t know if I missed something ?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
tom-zeitcommented, Aug 16, 2016

I have the same issue here

0reactions
syrusakbarycommented, Nov 15, 2016

This should be fixed in graphene-django:master. Closing here 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to properly use the "choices" field option in Django
I would suggest to use django-model-utils instead of Django built-in solution. The main advantage of ...
Read more >
Model field reference
This document contains all the API references of Field including the field options and field types Django offers. ... If the built-in fields...
Read more >
How to use Django Field Choices
Choices limits the input from the user to the particular values specified in models.py . If choices are given, they're enforced by model...
Read more >
Django models: Declaring a list of available choices in the ...
Based on django-model-utils we should create an instance of object Choices, as an argument passing tuples of allowed choices. Each tuple ...
Read more >
Populate choices from model
to django...@googlegroups.com. If you want your field to represent another model you should be using a foreign key, not a CharField regio =...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found