Fixed many to many relations in Django model

This commit is contained in:
Syrus Akbary 2016-01-11 16:50:05 +01:00
parent 84dbc58115
commit f68763b822
4 changed files with 9 additions and 1 deletions

View File

@ -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))

View File

@ -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)

View File

@ -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']
)

View File

@ -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):