Hi there, this is my first post on Google groups so forgive me if I have 
not followed proper etiquette.

I am in the process of building an API with DRF and so far things are going 
well. 

I decided originally to use HyperlinkedModelSerializer for my serializers 
because the URLs are a really great feature on the browsable API.

The issue I am having now is I need to send the URL for the related fields 
and I would rather send the IDs. 

Given this I have decided to keep the url for the specific resource being 
requested and use the IDs for the related objects.

Is it valid to use a ModelSerializer and include a url field in the fields 
and add the view_name in the extra_kwargs like the example below.

class MySerializer(serializer.ModelSerializer):
    class Meta:
        model = MyModel
        fields = ('url', 'user_id', 'other_fields')
        extra_kwargs = {
            'url': {'view_name': 'view name here'}
        }

Or should I rather use a HyperLinkedModelSerializer and explicitly set the 
related objects to PrimaryKeyRelatedFields?

I appreciate any feedback.

Regards,

Bradley

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to