A
A
Artyom Belousov2018-06-29 19:46:22
Django
Artyom Belousov, 2018-06-29 19:46:22

Is it possible to make a foreign key to different models?

Let's say in django I have an abstract ArtObject model that stands for a work of art. She has successors Song, Picture, Writing, which are similar but different. I want to add a Review model that fits all 3 models. There is an idea to make 2 IntegerField: one is responsible for the id of what the review is for, the other for the type of this something, but it looks like a crutch, which in fact it is. So, what is the best way to implement this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-06-29
@flygrounder

First, you can make a ForeignKey on the ArtObject itself. Secondly, your bike is already invented and is called GenericRelation .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question