carltongibson / neapolitan

Quick CRUD views for Django
https://noumenal.es/neapolitan/
MIT License
413 stars 30 forks source link

question : handling relationships foreign keys raw ids #34

Closed leonh closed 7 months ago

leonh commented 7 months ago

Hi, really like the general aim of this project.

I manage to get an example up and running against on of my models. The model has a number of relationships foreign key m2m to tables with 1000's of rows

Noticed that the forms output a big long select with all the options for foreign key fields for my model

In Django admin I have raw_ids option set for these

Is it beyond the scope of the project to add something like the raw_id ( ForeignKeyRawIdWidget) option in a Neapolitan view?

any guidance on how I might modify the Neapolitan view to add something similar to raw_ids?

thanks!

carltongibson commented 7 months ago

At first pass I'd say override get form class. Specify whatever widget you want for the FK field.

leonh commented 7 months ago

Thanks for the quick response. I'm working on it now.

A suggestion: Maybe allowing option to define a "widgets" dict on the CRUDView and pass that through to the modelform_factory() call by default (it accepts a "widgets" parameter).
Then you wouldn't need to override get_form_class

carltongibson commented 7 months ago

@leonh Yeah... I'm not going to add that...

The one right way to do it is (exactly) to override get_form_class() — that's clean enough. All kinds of weird and wonderful class options just get in the way.

Holding that line, and keeping the API minimal, is kind of what Neapolitan is all about.

Glad you're making progress. I'll close that now.