Skip to content Skip to sidebar Skip to footer

I'm Getting __init__() Takes At Least 2 Arguments (1 Given) On Integerfield

This is my models.py I'm getting a argument not enough in init def I know there are many similar questions like this but I can't find the solution there. class ExpField(models.Floa

Solution 1:

Remove the positional exp_field argument from the constructor's signature and get the field from the kwargs dict:

class LevelField(models.IntegerField):

    def __init__(self, *args, **kwargs):
        if kwargs.get('default') is None:
            kwargs['default'] = 1
        self.exp_field = kwargs.pop('exp_field', None)
        super(LevelField, self).__init__(*args, **kwargs)

Post a Comment for "I'm Getting __init__() Takes At Least 2 Arguments (1 Given) On Integerfield"