Saikat
Saikat

Reputation: 2633

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:

  1. 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.

  2. 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!

Upvotes: 1

Views: 959

Answers (2)

arie
arie

Reputation: 18982

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.

Upvotes: 0

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>

Upvotes: 1

Related Questions