I study flask-security . Quickstart has this code:

 class UserRoles(db.Model): # Because peewee does not come with built-in many-to-many # relationships, we need this intermediary class to link # user to roles. user = ForeignKeyField(User, related_name='roles') role = ForeignKeyField(Role, related_name='users') name = property(lambda self: self.role.name) description = property(lambda self: self.role.description) 

I just can't understand what the strings do

 name = property(lambda self: self.role.name) description = property(lambda self: self.role.description) 

Where does the property function come from, and in general, what happens in these lines?

    1 answer 1

    property is a standard python function. Allows you to work with an attribute of an instance of a class, assigning various actions to set, change, delete it. Read more in the documentation.

    In this case, it's just the equivalent of the decorator version.

     class Foo(object): # для примера role = '123' @property def name(self): return self.role >>> Foo().name '123' 

    It just did not make sense to paint the full version of this design, and this property is the usual syntactic sugar to get self.role.name

    • Maybe you can tell me where I can see an example of the finished authorization using flask-security? That there were just a couple of html and mini-python code. I just can't figure it out ... - faoxis