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
Related Q & A:
- What's the best way to get a job in a restaurant?Best solution by Yahoo! Answers
- What's the best way to get smudges off of a plasma?Best solution by Yahoo! Answers
- What is the best way to find new members for a yahoo group?Best solution by Yahoo! Answers
- What is the best way to get back links to a website?Best solution by Yahoo! Answers
- What is the best way to negotiate a salary for a new position?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.