Closed bertonoronha closed 9 years ago
Can you give me a code example that causes this error?
I add:
from rest_framework_msf.fields import MultiSlugRelatedField
class IExampleSerializer(serializers.HyperlinkedModelSerializer):
id = serializers.IntegerField(read_only=True)
metabolites = serializers.SlugRelatedField(
many = True,
read_only = True,
slug_fields = ('met_id','abbreviation')
)
class Meta:
model = IEM
Still not sure I have enough to diagnose this. Can you show me some code that uses this serializer and produces the error, or a copy/paste of the full stacktrace?
class IEMSerializer(serializers.HyperlinkedModelSerializer):
id = serializers.IntegerField(read_only=True)
metabolites = serializers.SlugRelatedField(
many = True,
read_only = True,
slug_fields = ('met_id','abbreviation')
)
class Meta:
model = IEM
This is the serializer that I am using in this view:
class IEMViewSet(viewsets.ModelViewSet):
queryset = IEM.objects.all()
serializer_class = IEMSerializer
filter_backends = (filters.SearchFilter,)
search_fields = ('name',)
urls registered as:
router.register(r'iems', views.IEMViewSet)
When I try to access the page via localhost:8000/iems/ the stacktrace I get is this:
AssertionError at /iems/
Request Method: GET
Request URL: http://localhost:8000/iems/
Django Version: 1.7.1
Exception Type: AssertionError
Exception Value:
The `slug_field` argument is required.
Exception Location: C:\Users\alberto.noronha\AppData\Local\Continuum\Anaconda\lib\site-packages\rest_framework\relations.py in __init__, line 300
Python Executable: C:\Users\alberto.noronha\AppData\Local\Continuum\Anaconda\python.exe
Python Version: 2.7.7
...
Stacktrace: http://dpaste.com/32Y786Q
I can post more code if needed, and thanks for the help!
Hilarious, I completely overlooked it. You are not actually using the MultiSlugRelatedField
. You're using the built-in SlugRelatedField
.
Lemme know if that doesn't fix it. Marking this closed.
Yes, I thought that was it was supposed to be as it is like that in the documentation. . When I use it I get an error like:
'module' object has no attribute 'MultiSlugRelatedField'
I guess this is a problem with the import then.
Yes, docs may be wrong. Correct import should be from rest_framework_msf.fields import MultiSlugRelatedField
Hello there,
Thank you for taking the time to develop this extension! However, I have a problem when trying to use multiple slug fields.
I add the requirement in the serializers.py:
from rest_framework_msf.fields import MultiSlugRelatedField
Then I add two fields in the slug_fields argument, and I get an error saying that The
slug_field
argument is required.Am I doing something wrong? I followed the documentation, but maybe I missed something.
Thanks!