Django Model charField with choices : query field
See original GitHub issueI 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:
- Created 7 years ago
- Comments:5 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have the same issue here
This should be fixed in
graphene-django
:master
. Closing here 😃