6

The field validation process can happen in 'Django Model level field declaration' or in 'Deserialization of data on DRF serialization section'. I have the following concerns regarding this validation process:

  • What is the separation of concerns? Which validation section should be placed where?
  • How the DRF serialization section restricts manual database entry with the validation?
RaiBnod
  • 2,141
  • 2
  • 19
  • 25

2 Answers2

4

Serializers are concerned with translating information to/from different formats for a model (text/json, etc.), and so the validation is in reference to this.

Model validation is a lower-level check, where the creation/modification of a db model is done. I always have model validation, even if I have serialization validation.

A. Rose
  • 470
  • 2
  • 7
-1

I think the difference can be understood with the following example .

Let's say a college A has maxmimum seats available are 200 in CS Stream and college B has maximum seats 500 for CS stream for this scenerio field validation at serializers makes sense

Now let's assume if there is a restriction on the number of student that are allowed in CS Stream for all colleges the we should use the Model level field validation

I hope this helps

Sachin Rajput
  • 238
  • 7
  • 26