Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7700225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:39:34+00:00 2026-05-31T22:39:34+00:00

I use flask with flask-peewee and wtfpeewee. So, I have models like that: class

  • 0

I use flask with flask-peewee and wtfpeewee.
So, I have models like that:

class Category(Model):
    name = CharField()
    user = ForeignKeyField(User, null=True)

class Record(Model):
    value = DecimalField()
    category = ForeignKeyField(Category)
    user = ForeignKeyField(User)

When I create form for user to add Record, I do it that way:

RecordForm = model_form(Record)

All categories in database are available for choice in field ‘Category’ of this form, but I need to limit available choices for ‘Category’ field to a subset of categories that have user field equal None or current (logged in) user. I know how to limit it by query, but how should that be done for a form field?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T22:39:35+00:00Added an answer on May 31, 2026 at 10:39 pm

    Sorry to see this just now

    You can do this at class definition time:

    from wtfpeewee.fields import SelectQueryField
    
    class MyForm(Form):
        category = SelectQueryField(query=Category.filter(some_val=other_val)
    

    Alternatively, I believe you can do this at runtime:

    my_form = MyForm()
    my_form.category.query = Category.filter(user=some_user)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that will use flask and mongodb; I will probably host
In Flask-PyMongo, they use self._Collection__database to represent the database object that this Collection object
I'm using flask as a python framework with sqlalchemy. The models use the query_property
I have a Python/Flask webapp with MongoDB database on DotCloud hosting. I would like
I have written a small webapp using the flask framework that involves plotting using
as you all know that if we use flash object in web page in
Does websites created by Flex Builder works on every browsers that use Flash ?
In a flask application I wrote, I make use of an external library which
I am working on a Flask extension that adds CouchDB support to Flask. To
I have a Flask, SQLAlchemy webapp which uses a single mysql server. I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.