It'd probably make more sense they wrote it this way
User.profile = property(lambda self: self.get_profile())
Or more verbosely:
class UserProfile(models.Model):
user = models.OneToOneField(User)
@property
def profile(self):
return self.get_profile()
def __str__(self):
return "%s's profile" % self.user
The first argument of every instance method of a Python object is the instance of the class to which the method belongs. self
is just a convention, so u
works just as well.