Object has no attribute _state

后端 未结 2 532
慢半拍i
慢半拍i 2020-12-20 11:08

I\'m developing Django application, and I have following error

\'Sheep\' object has no attribute _state

My models are constructed like this

2条回答
  •  情话喂你
    2020-12-20 12:10

    Django docs recommend against you to use __init__ method in models:

    You may be tempted to customize the model by overriding the __init__ method. If you do so, however, take care not to change the calling signature as any change may prevent the model instance from being saved. Rather than overriding __init__, try using one of these approaches:

    1. Add a classmethod on the model class
    2. Add a method on a custom manager (usually preferred)

提交回复
热议问题