tags:

views:

38

answers:

2

OK, so let me give you an overview first. I have this site and in it there is a form section. When you access that section you can view or start a new project. Each project has 3-5 different forms.

My problem is that I don't want viewers to have to go through all 3-5 pages to see the relevant information they need. Instead I want to give each project a main page where all the essential data entered into the forms is shown as non-editable data. I hope this makes sense.

So I need to find a way to access all that data from the different forms for each project and to feed that data into the new page I'll be calling "Main". Each project will have a separate main page for itself.

I'm pretty much clueless as to how I should do this, so any help at all would be appreciated.

Thanks

A: 

You could try this. After that, you could:

If you've already seen all that, then:

First, you should create a view for your main page. So if you have an application my_app, my_app/views.py should be like:

def main_page_view(request, project_name):
    # Your code here
    pass

Then, to use this, you'd modify urls.py and add in something like:

(r'^projects/(?:<project_name>[a-zA-Z0-9]+)', 'my_app.views.main_page_view'),

Also, you'd need models, which are created in models.py, by subclassing django.models.Model

EDIT: re-reading your question, I guess you need this

Aviral Dasgupta
Thanks for that answer. I'm already made the different forms/models/views for the forms I have and they are functional. My problem is that I want the data entered into them to show up on a different page. So if you fill out form 1, I want that data to show up on the main page for that project as non editable data.In other words, I need to somehow access the database and grab the information for each project and feed it out through the main page. I just don't know how.
Pedram E
Submit the form, get the data, and redirect to the next form...
Aviral Dasgupta
A: 

Data can be passed from a view to a template through the context.

So say you create a summary view...

def summary(request, *args, **kwargs):

In that view you can query the database using the model api and pass the result of that query into the template for rendering. I'm not sure what your models look like, but say you had a model that had a title and the owner (as a ForeignKey to user)...

class Project(models.Model):
    title = models.CharField(max_length=250)
    user = models.ForeignKey(User)

Your model will be obviously be different. In your view you could query for all of the models that belong to the current user...

def summary(request, *args, **kwargs):
    projects = Project.objects.filter(user=request.user)

Once you've gathered that, you can pass in the query to the template rendering system...

def summary(request, *args, **kwargs):
    projects = Project.objects.filter(user=request.user)
    render_to_response('project_summary.html', {'projects': projects }, ... )

When you pass the query to the template, you've named it projects. From within the template you can access it by this name...

<body>
    <table>
    {% for project in projects %}
        <tr><td>{{ project.title }}</td></tr>
    {% endfor %}
    </table>
</body>

(Notice also how you can access a property of the model from within the template as well.)

T. Stone
Thanks. I'll try your suggestion. I'm wondering though, because each form will be field out many times for the different projects would this just show the data for that specific project or will it show the data for all the projects at once? The one I'm looking for is to have only the data for that specific project to show up.
Pedram E
You can control what data is showing up though adjusting the query. If you haven't yet read all the way through the Django book, I highly recommend doing so. It only takes about 12-14 hours to go all the way through, and it's well worth the investment.
T. Stone