[Fixed]-Dynamic queryset for foreignKey in Single Page Application with Django

1👍

You need to specify that the model_1 field of Model2 can be null, as specified here:
Allow null in foreign key to user. Django

model_1 = models.ForeignKey(Model1, null=True, blank=True, default = None)

0👍

I find out how to handle that problem. It is quite stupid, I did not give you all the parameters of the problem.

The forms are rendered on load but when I validate it, it goes through a CRUD operation and an OTHER form is initialized at this point which will handle the data I’m sending. So I can override the queryset in the init of that (second) form based on some extra kwargs to differentiate between the form I’m using for the first rendering and the form to handle my data.

No need to make any field nullable or add extra validation.

Hope I’m clear enough. Cheers

Leave a comment