mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-22 17:46:57 +03:00
Fixed many to many relations in Django model
This commit is contained in:
parent
84dbc58115
commit
f68763b822
|
@ -58,6 +58,7 @@ def convert_field_to_float(field):
|
|||
|
||||
@convert_django_field.register(models.ManyToManyField)
|
||||
@convert_django_field.register(models.ManyToOneRel)
|
||||
@convert_django_field.register(models.ManyToManyRel)
|
||||
def convert_field_to_list_or_connection(field):
|
||||
from .fields import DjangoModelField, ConnectionOrListField
|
||||
model_field = DjangoModelField(get_related_model(field))
|
||||
|
|
|
@ -7,6 +7,11 @@ class Pet(models.Model):
|
|||
name = models.CharField(max_length=30)
|
||||
|
||||
|
||||
class Film(models.Model):
|
||||
reporters = models.ManyToManyField('Reporter',
|
||||
related_name='films')
|
||||
|
||||
|
||||
class Reporter(models.Model):
|
||||
first_name = models.CharField(max_length=30)
|
||||
last_name = models.CharField(max_length=30)
|
||||
|
|
|
@ -29,7 +29,7 @@ def test_should_map_fields_correctly():
|
|||
model = Reporter
|
||||
assert_equal_lists(
|
||||
ReporterType2._meta.fields_map.keys(),
|
||||
['articles', 'first_name', 'last_name', 'email', 'pets', 'id']
|
||||
['articles', 'first_name', 'last_name', 'email', 'pets', 'id', 'films']
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -35,6 +35,8 @@ def get_reverse_fields(model):
|
|||
yield new_related
|
||||
elif isinstance(related, models.ManyToOneRel):
|
||||
yield related
|
||||
elif isinstance(related, models.ManyToManyRel) and not related.symmetrical:
|
||||
yield related
|
||||
|
||||
|
||||
class WrappedQueryset(LazyList):
|
||||
|
|
Loading…
Reference in New Issue
Block a user