Django Admin Interface: how to show different model based on a user's selection?
I am creating a Poll application using Django. The workflow for the Admin user is as follows:
Admin clicks on the "Add Question" which shows the Admin a simple page with a dropdown list of 3 types(True/False,Multiple choice, Single choice) of Questions she can 开发者_运维技巧create. Basically there will be 3 types of Question Models for each of the kind.
Based on the Admin's selection from the dropdown list, that particular model is shown and the admin can enter values for different fields of that model.
That's all! Seems pretty basic, but being a newbie in Django I can't find a solution. Any help will be greatly appreciated.
Thanks!
This isn't really behavior you can expect to be baked into django.
Take advantage of what django does ship with, the CRUD interfaces, and set up a start page that has a drop down list that redirects to the appropriate model via some JavaScript.
<script>
// I'm using jQuery since I can type it as fast as pseudo code...
$(function() {
$("select").change(function() {
window.location = $(this).val();
})
})
</script>
<select>
<option value="{% url admin:myapp_mymodel1_add %}">Model 1</option>
<option value="{% url admin:myapp_mymodel2_add %}">Model 2</option>
<option value="{% url admin:myapp_mymodel3_add %}">Model 3</option>
</select>
Do you have to use the admin for this? I think a series of common forms would serve you better if you want to create a custom workflow which involves processing the data of multiple forms.
You could tie your forms together using Django's FormWizard.
精彩评论