I have not posted all the objects involved with this as that would make for 
a lot of code. If needed will provide. 

I am trying to serialize an object using a custom defined 
HyperlinkRelatedField. The subclass is required to get the correct object 
to link to--class contains two objects for each item, a "Draft" object, and 
the "Published" object. 

For example, the base model: 

PK    Object               Status        Slug
1       EventSeries A   Draft          eventseries-a
14     EventSeries A   Published  eventseries-a
2       EventSeries B   Draft          eventseries-b
22     EventSeries B   Published  eventseries-b

By default the "draft" event is returned, so this initial override is done 
in get_queryset method.

However, for each Event Series there can be 0, n related Event objects 
which also have a draft and published version. 

These are related to the EventSeries model using a custom 
HyperlinkedRelatedField. This enables me to use the get_object method to 
return the published object instead of the draft.

This works perfectly as long as there are associated Event objects. When 
there are none, I am getting the error Cannot resolve URL for hyperlinked 

I have tried adding allow_null=True, allow_blank=True to the custom 
HyperlinkedRelatedField but neither help. 

Alternatively, is there a way to override the to_representation method in 

Thanks in advance for your help.

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 django-rest-framework+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to