[PYTHON] Instantly convert Model to Dictionary with Django and initialize Form at explosive speed

Overview

I decided not to use ModelForm due to various reasons, but when initializing Form with Model, it was awkward to give it as a Dictonary type as an argument of the constructor, so a memo when I checked

How to do

Just call the __dict __ method of the Model object.

Example

model = Compound.objects.get(id=compound_id)
form = CompoundForm(compound.__dict__)

References describe various other methods.

References

Convert Django Model object to dict with all of the fields intact

Recommended Posts

Instantly convert Model to Dictionary with Django and initialize Form at explosive speed
Convert PIL format images read from form with Django to base64 format
Convert memo at once with Python 2to3
Convert DICOM to PNG with Ascending and Descending
Tutorial to infer the model learned in Tensorflow with C ++/OpenVINO at high speed
How to convert a class object to a dictionary with SQLAlchemy
Implement APIs at explosive speed using Django REST Framework
Calculate Gaussian kernel at explosive speed even with python
Try to solve Sudoku at explosive speed using numpy
I tried to build a service that sells machine-learned data at explosive speed with Docker
Convert 202003 to 2020-03 with pandas
Convert RGB and HSV in a differentiable form with PyTorch
How to convert an array to a dictionary with Python [Application]
How to scrape at speed per second with Python Selenium
Read json in C # and convert to dictionary type (forced)
Convert video to black and white with ffmpeg + python + opencv
[Django] Redirect to previous page after submitting with POST form
What non-programmers and web app development beginners should do to clear GeoDjango tutorials at explosive speed