3👍
✅
Since it looks like nobody has an answer to this, I’m going to go ahead and “answer” it.
The answer I’ve found is that you cannot have non-model fields in a model-form. They are simply ignored by the framework. Adding your own forms inline also doesn’t seem to work well, the same errors end up occurring.
The way I fixed this issue was:
- Create A CSV Preview Widget
- Implement the Widget into a CSV Field
- Write the field/widget logic
- Create my own form — NOT a model-form
- Create Form handlers
- Create view to host the form
- Override add_view in models to return the custom form
- Override the get_form function in models to add the csv widget to the form
I don’t really -Like- this answer, but I don’t have any better solution.
0👍
If you are not too picky on the implementation you might want to look at something like Postgres Foreign data wrappers (file_fdw is a csv interface). Since the files are very uniform, you will get a nice ORM interface and save a ton of headaches on the import side.
- [Django]-User Authentication in Django
- [Django]-Enable dirty reads for single transaction in Django
- [Django]-Django redirect inside a function
- [Django]-Is Docker an alternative for 'virtualenv' while develping Django project?
Source:stackexchange.com