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
Just call the __dict __
method of the Model object.
model = Compound.objects.get(id=compound_id)
form = CompoundForm(compound.__dict__)
References describe various other methods.
Convert Django Model object to dict with all of the fields intact
Recommended Posts