What does a promotional model do?

In Django, what is the best way to reference another model in a model instance?

  • I have a Django model, we'll call it List. In the List model, I want to make a user-selectable reference to another model. This way, in the admin, a user could create a new instance of List, and choose from a selection of all the models. Say there are models called User, Site, Post, and Comment. Once the user adds a new List one of the options they have is a choice field that lists User, Site, Post, and Comment. The view code for the List should then be able to figure out which model a particular List instance references and perform queries on that model.

  • Answer:

    if I understood correctly you just want to choose a model and then query that table elsewhere, you don't have a relationship among those on the data itself so I would simply use a field with the 'choices' parameter and then select it on the view based on that.

Michael Cetrulo at Quora Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.