Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to choose db column name instead of field name for foreign keys in form validation? #42

Open
AnastassiyaP opened this issue Jul 12, 2018 · 3 comments

Comments

@AnastassiyaP
Copy link

If the answer is no - is there some plans to add this possibility in the future?

@coleifer
Copy link
Owner

What do you mean "choose db column name"? Why would this be necessary?

@AnastassiyaP
Copy link
Author

For foreign keys, the method validate() of the object, created by the model_form method, requires field without '_id': region instead of region_id for example.
I would prefer to pass and validate field with the name region_id somehow. As the names like 'region' may cause misunderstanding for a new user of the api: You cannot be sure without reading the documentation, if this field is a link to another object 'region', or just a text field.

I wrote the converter that do the thing that I want, but maybe there is a better way to do the same.

class Converter(ModelConverter):

    def convert(self, model, field, field_args):
        name,field_obj = ModelConverter.convert(self, model, field, field_args)
        return FieldInfo(field.column_name, field_obj)

@coleifer
Copy link
Owner

You know, it's been so long since I worked with wtforms that I'm not sure how to advise you.

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

No branches or pull requests

2 participants