@@ -11,6 +11,7 @@ this mixin definitely suits you.
1111- [ Advanced usage] ( #Advanced-usage )
1212- [ Custom formats] ( #Custom-formats )
1313- [ Custom types] ( #Custom-types )
14+ - [ Custom Serializer] ( #Custom-serializer )
1415- [ Timezones] ( #Timezones )
1516- [ Troubleshooting] ( #Troubleshooting )
1617- [ Tests] ( #Tests )
@@ -304,6 +305,27 @@ Unfortunately you can not access formats or tzinfo in that functions.
304305I' ll implement this logic later if any of users needs it.
305306
306307
308+ # Custom Serializer
309+ To have full control over the Serializer, you can define your own subclass with custom logic, and then configure the mixin to use it.
310+ ```python
311+ from sqlalchemy_serializer import Serializer, SerializerMixin
312+
313+
314+ class CustomSerializer(Serializer):
315+
316+ def serialize_model(self , value) -> dict :
317+ """ Custom override adding special case for a complex model."""
318+ if isinstance (value, ComplexModel):
319+ return complex_logic(value)
320+ return super ().serialize_model(value)
321+
322+
323+ class CustomSerializerMixin(SerializerMixin):
324+
325+ serialize_class = CustomSerializer
326+ ```
327+
328+
307329# Timezones
308330To keep `datetimes` consistent its better to store it in the database normalized to ** UTC ** .
309331But when you return response, sometimes (mostly in web, mobile applications can do it themselves)
0 commit comments