serialization - Getting the "latest" field in a set to serialize in Django Rest Framework -


my current serializer looks so:

class bareboneentityserializer(serializers.modelserializer):     class meta:         model = entity         fields = (             'id', 'label', 'related_yid_count', 'description',         ) 

there 1 set: entityclassification_set now, in other serializer have so:

entityclassification_set = entityclassificationserializer(many=true) 

but after time, realized need "latest" or last element in set, how can add field serializer? adding property way go this? or there way it?

right can this

@property def classification(self):     return entityclassification.objects.filter(entity=self).latest() 

but way it?

entities = entity.objects.order_by('-id')[:5] entityclassification_set = entityclassificationserializer(entities, many=true) 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -