CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-flask-admin

Simple and extensible admin interface framework for Flask

86

1.30x

Quality

Pending

Does it follow best practices?

Impact

86%

1.30x

Average score across 10 eval scenarios

Overview
Eval results
Files

task.mdevals/scenario-9/

Product Inventory Admin Interface

Build a Flask application with an admin interface for managing product inventory. The admin interface should handle form validation and display appropriate error messages to users.

Requirements

Create a Flask application with a single model Product that has the following fields:

  • id: Integer, primary key
  • name: String, required, maximum 100 characters
  • sku: String, required, must be unique, maximum 50 characters
  • price: Float, required, must be positive
  • quantity: Integer, required, must be non-negative
  • email: String, optional, must be a valid email format when provided

Implement an admin interface that:

  • Provides forms for creating and editing products
  • Validates all fields according to the requirements above
  • Displays user-friendly error messages when validation fails
  • Handles database constraint violations (e.g., duplicate SKU) gracefully
  • Customizes field labels to be more user-friendly (e.g., "SKU" instead of "sku")

Implementation

@generates

API

from flask import Flask
from flask_sqlalchemy import SQLAlchemy

# Initialize Flask app and database
app = Flask(__name__)
db = SQLAlchemy()

# Product model
class Product(db.Model):
    """Product model for inventory management."""
    pass

# Configure and initialize admin interface
def setup_admin(app, db):
    """Set up the admin interface with proper validation."""
    pass

Test Cases

Valid product creation

  • Creating a product with name="Laptop", sku="LAP-001", price=999.99, quantity=10, email="supplier@example.com" succeeds without errors @test

Required field validation

  • Attempting to create a product without a name displays an error message indicating the name field is required @test
  • Attempting to create a product without a price displays an error message indicating the price field is required @test

Field constraint validation

  • Attempting to create a product with a negative price displays an error message indicating the price must be positive @test
  • Attempting to create a product with a negative quantity displays an error message indicating the quantity must be non-negative @test
  • Attempting to create a product with an invalid email format displays an error message indicating the email is invalid @test

Unique constraint handling

  • Attempting to create a product with a SKU that already exists displays an error message indicating the SKU must be unique @test

Dependencies { .dependencies }

Flask { .dependency }

Web framework for Python

Flask-Admin { .dependency }

Provides admin interface framework with form validation support

Flask-SQLAlchemy { .dependency }

Provides SQLAlchemy integration for Flask

WTForms { .dependency }

Provides form handling and validation (used by Flask-Admin)

Install with Tessl CLI

npx tessl i tessl/pypi-flask-admin

tile.json