Answer the question
In order to leave comments, you need to log in
How to pass an object with a ForeignKey to Django views?
Let’s say I have views with the add_comment function (I didn’t think of a better idea for the example), but in the Comment model name = ForeignKey(Name)
, if it was without ForeignKey it would be like this
:
exam = Exam.objects.create(name = "hohohoh" , value="33223"),
but how to make such a function that would
exam = Exam.objects.create(name = "hohohoh", value="33223", AND HERE is what is passed through Foreign Key)
Answer the question
In order to leave comments, you need to log in
Why not make it static then?
Singleton is not the only method of interaction between classes (and in general this is not about interaction, but oh well, the essence is clear). Read about dependency injection (without frameworks), for example.
In the same unit, you can use SerializeField, GetComponent, and the hated FindObjectOfType to the heap,
instance_name = Name.objects.first()
Exam.objects.create(name = "hohohoh", value="33223", name=instance_name)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question