The problem with the generated fields in flask-admin. There is a model

class Article(db.Model, Base): id = db.Column(db.Integer(), primary_key=True) title = db.Column(db.String()) description = db.Column(db.Text()) url = db.Column(db.String()) created_on = db.Column(db.DateTime(), server_default=db.func.now()) updated_on = db.Column(db.DateTime(), server_default=db.func.now(), onupdate=db.func.now()) author = db.Column(db.Integer(), db.ForeignKey('user.id')) category = db.Column(db.Integer(), db.ForeignKey('category.id')) def __init__(self, title="", description="", author="", category=""): self.title = title self.author = author self.category = category self.description = description self.url = slugify(title) 

The form passes 4 values ​​(title, description, author, category), 5 field (url) should be generated by itself (self.url = slugify (title)), but this does not happen

This form was generated by flask-admin. enter image description here

    1 answer 1

    Create a method such as save (), and already in it make manipulations:

     @staticmethod def save(self, *args, **kwargs): if not self.url: self.url = slugify(self.title) super(Article, self).save(*args, **kwargs) 

    PS I'm not sure that the method I wrote will work as it should, but in general you can do what you want in exactly the same way.