Initial Value In Form's __init__ For The Model With Generic Relation
I have a model with generic relation like this: content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE, blank=True, null=True) object_id = models.PositiveInteg
Solution 1:
I have found a nice answer to my question here:
If you have already called super().init in your Form class, you should update the form.initial dictionary, not the field.initial property. If you study form.initial (e.g. print self.initial after the call to super().init), it will contain values for all the fields. Having a value of None in that dict will override the field.initial value
The solution to the problem was then just adding one additional line:
self.initial['content_object'] = form_value
Post a Comment for "Initial Value In Form's __init__ For The Model With Generic Relation"