
The product endpoint used to hand-build its response dicts and pick fields out of the raw request body, so field types drifted between endpoints and malformed input reached the database. Declare one plain Serializer with typed, constrained fields, so instances render to the defined payload, input is refused field by field, and save routes to create or update.
Read the full problemA hand-typed serializer restates its model's fields, drifts out of step with the columns after every change, and lets a client overwrite the values the server owns. Derive it from the model instead, with an explicit field list, read-only server-managed values, a write-only cost, and the taken sku answered as a field error.
Read the full problemAppointments that start in the past or end before they start reach the clinic's database because the serializer only checks types, and a partial edit is waved through unchecked. Layer the field rule, the cross-field rule and one shared count rule onto the serializer so every submitted value is judged, whether the update is whole or partial.
Read the full problemA room-booking service checks nothing a client sends it, so a stay in the past, a stay that ends before it begins, a party larger than the room sleeps and a reference somebody already has all reach the database or corrupt a booking on the way. Build the whole payload layer: a booking serializer derived from the model with an explicit field set, server-owned values, a write-only note, field and cross-field rules, and a plain serializer for the availability query.
Read the full problem