You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
according to the default github example, default behavior for many to many relation ship is to give IDs in the corresponding field, and add a route to the details in the links field:
# The SerializerclassUserSerializer(DynamicModelSerializer):
classMeta:
model=Username='user'fields= ("id", "name", "location", "groups")
location=DynamicRelationField('LocationSerializer')
groups=DynamicRelationField('GroupSerializer', many=True)
# The ViewSetclassUserViewSet(DynamicModelViewSet):
serializer_class=UserSerializerqueryset=User.objects.all()
groups gave IDs [1,2] and you have the root to get more information in the field link>groups as /users/1/groups
But when i setup a basic app:
classIngredient(models.Model):
""" A ingredient that can be a base or and ingredient. A base ingredient is the base word you search descriptive for or alts Base don't have tag and ingredients can have multiple adjective tags """classIngredientType(models.IntegerChoices):
BASE=0, _('Base')
INGREDIENT=1, _('Ingredient')
name=models.TextField()
ingredient_type=models.IntegerField(choices=IngredientType.choices)
tags=models.ManyToManyField(to='core.Tag', related_name='ingredients')
alts=models.ManyToManyField(to='core.Ingredient', blank=True)
def__str__(self) ->str:
returnself.IngredientType(self.ingredient_type).label+': '+self.nameclassTag(models.Model):
""" A tag represent a qualitative of an ingrediant. A tag can have multiple ingredients, and an ingredient can have multiple tags. """name=models.TextField()
def__str__(self) ->str:
returnself.nameclassIngredientSerializer(serializers.DynamicModelSerializer):
tags=serializers.DynamicRelationField('TagSerializer', many=True, deferred=False)
alts=serializers.DynamicRelationField('IngredientSerializer', many=True, deferred=False)
classMeta:
model=Ingredientfields= ('id', 'name', 'ingredient_type', 'tags', 'alts')
classTagSerializer(serializers.DynamicModelSerializer):
classMeta:
model=Tagfields= ('id', 'name', 'ingredients')
ingredients=serializers.DynamicRelationField("IngredientSerializer", many=True)
classIngredientViewSet(viewsets.DynamicModelViewSet):
""" API endpoint that allows Ingredients to be viewed or edited. """queryset=Ingredient.objects.all().order_by('name')
serializer_class=IngredientSerializerpermission_classes= [permissions.IsAuthenticatedOrReadOnly]
classTagViewSet(viewsets.DynamicModelViewSet):
queryset=Tag.objects.all().order_by('name')
serializer_class=TagSerializerpermission_classes= [permissions.IsAuthenticatedOrReadOnly]
Hello,
according to the default github example, default behavior for many to many relation ship is to give IDs in the corresponding field, and add a route to the details in the links field:
groups gave IDs [1,2] and you have the root to get more information in the field link>groups as /users/1/groups
But when i setup a basic app:
i have this result:
Did i've missed something in the doc ?
The text was updated successfully, but these errors were encountered: