79548326

Date: 2025-04-01 10:21:58
Score: 1
Natty:
Report link

In addition to @sj95126's comment.

What does the deconstruct method do:

... - in particular, what arguments to pass to __init__() to re-create it.

For example, in our HandField class we’re always forcibly setting max_length in __init__(). The deconstruct() method on the base Field class will see this and try to return it in the keyword arguments; thus, we can drop it from the keyword arguments for readability:

Consider the following examples:

from django.db import models

class ModelOne(models.Model):
    hand = HandField(max_length=50)

class ModelTwo(models.Model):
    hand = HandField()

So, whether you pass max_length or not, the value is same for
ModelOne and ModelTwo because it has already been pre-defined
in the __init__ initialiser.

It is dropped for readability. Dropping it or not doesn't matter
because it is always defined in __init__.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @sj95126's
  • Low reputation (1):
Posted by: Bazzan