Skip to content

Conversation

@audreyfeldroy
Copy link
Member

I've extended Pydantic's BaseModel to create AirModel and give it a .form method. That way we can generate the AirForm from the AirModel.

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • New feature
    • Core Air (Air Tags, Request/Response cycle, etc)
    • Optional (Authentication, CSRF, etc)
    • Third-Party Integrated (Cookbook documentation on using Air databases or a task manager, etc)
    • Out-of-Scope (Formal integration with databases, external task managers, or commercial services etc - won't be accepted, please create a separate project)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

Pull request tasks

The following have been completed for this task:

  • Code changes
  • Documentation changes for new or changed features
  • Alterations of behavior come with a working implementation in the examples folder
  • Tests on new or altered behaviors

Checklist

  • I have run just test and just qa, ensuring my code changes passes all existing tests
  • I have performed a self-review of my own code
  • I have ensured that there are tests to cover my changes

Demo or screenshot

examples/demo_form_errors.py

Introduces the model_form() utility to generate AirForm subclasses from Pydantic models, and adds AirModel.form() for convenient form creation. Updates demo and tests to use the new helpers, supporting field inclusion and custom widgets.
@codecov
Copy link

codecov bot commented Oct 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Co-Authored-By: Daniel Roy Greenfeld <[email protected]>
Copy link
Member

@pydanny pydanny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's so impressive about this PR is how it barely touches existing code yet is transformative. This will vastly reduce the volume of code required to work in forms.

src/air/forms.py Outdated
) # ty: ignore[no-matching-overload]


def model_form(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like how this is its own function. This makes adding this functionality much easier to test.

@pydanny
Copy link
Member

pydanny commented Oct 31, 2025

WTF, all the commits came over to my name. I need to restore attribution to @audreyfeldroy.

Also, there's an extra instantiation in there that could be removed. Changing this to draft while I figure out the attribution and instatiation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants