Reputation: 3829
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)
Upvotes: 11
Views: 7354
Reputation: 363566
Just remove the @property
decorator. If you need to accept arguments, it's not a property.
Upvotes: 24