1👍
You have the wrong placement:
class MyModelSerializer(serailizers.ModelSerializer):
class Meta:
model = MyModel
fields = "__all__"
hrs = serializers.SerializerMethodField()
def get_hrs(self, obj):
datetime = SomeModel.objects.filter(id=obj.id).last().datetime
now = datetime.now()
return (now - datetime).total_seconds() // 3600
Source:stackexchange.com