Search code examples
pythonflaskpeeweeflask-peewee

Looking for a simple way to implement a Simple Update records on My flask application using pewee


So I have controller Page when i defined different functions like adding new records. How ever i want to add a function on how to edit the existing records in a database.

    def addNewAsset(self, request):
        # connection = Database_Connection('Asset_Register')
        AssetID = request.form['AssetID']
        Description = request.form['Description']
        Brand = request.form['Brand'] 

        asset_dtls = AssetDetails(
            AssetID=AssetID,
            Description=Description,
            Brand=Brand,
            Model=Model,
            
        )
        return asset_dtls.save(True)```

Solution

  • You would:

    1. fetch the record from the database, e.g. AssetDetails.get(...)
    2. populate the form widgets in the template w/the record data
    3. on POST, take the form data and update the record from step 1.