I've the following models in Django.
class User(models.Model):
name = models.CharField(max_length=50)
...
...
@property
def get_info(self, key=None):
value = self.name if key else 'Hello World'
return value
But when I try to execute the code in Django shell, I'm getting the following error.
n [4]: user = User.objects.get(id=1)
n [5]: user.get_info(key='test_key')
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-5-f7b917070aee> in <module>()
----> 1 user.get_info(key='test_key')
TypeError: _get_info() takes exactly 2 arguments (1 given)
Just remove the @property
decorator. If you need to accept arguments, it's not a property.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With