Why does adding this __init__() method break my Django model?

后端 未结 3 833
情话喂你
情话喂你 2021-01-23 07:13

This question is a follow-up to one I asked earlier here.

I have a Django model as follows:

class MyModel(models.Model):
    my_field1 = models.DateTimeF         


        
3条回答
  •  攒了一身酷
    2021-01-23 08:13

    You don't need to use __init__ in Django models, instead use Meta class

    class MyModel(models.Model):
        my_field1 = models.DateTimeField(default=datetime.utcnow, editable=False)
        my_field2 = models.DateTimeField()
    
        class Meta:
            verbose_name = 'My Model'
            verbose_name_plural = 'My Models' # and so on
    

提交回复
热议问题