2

I think that is the right way to ask it. I'm wondering which parts of the code execute first, second, etc.

My assumption would be, but I don't know:

  1. Request
  2. Middleware
  3. View
  4. Model
  5. Middleware
  6. Response

The reason I'm asking is because I want something to happen dynamicall in the Model based on a request variable and I'm trying to device the best way to automatically add the request in to the model layer without passing in via the views. I would assume that some sort of middleware fantastic contraption would be the way to do it somehow.

orokusaki
  • 55,146
  • 59
  • 179
  • 257
  • Can you be just a little more specific? "Adding the request into the model layer without passing in via the views" doesn't quite make sense to me. What is it in the request that you are trying to communicate to the model? – Peter Rowell Jan 29 '10 at 05:46
  • I'm trying to view who the current request.user is inside models.py so ghat I can use a custom manager for filtering based on the user. – orokusaki Jan 29 '10 at 06:25

3 Answers3

4

To answer your clarification comment -- You can't get there from here.

models.py is just a file where you put model classes, which are just classes that get accessed from all over the place. Unless the request object is passed to the function you're working with, then it does not exist, and there is no request.user. Models can be used from anywhere, not just from within contexts where there's a request.

If you need to work with the request object, then pass it as a parameter. And if that doesn't make sense, then you're using your model wrong.

tylerl
  • 30,197
  • 13
  • 80
  • 113
1

Neither the model nor the templates are ever part of the stack. Do your work in a view.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
1

I think it's more like:

  1. Request
  2. Middleware (URL mapper)
  3. View
    1. Model (if requested by the view)
    2. Template (if requested by the view)
  4. Middleware (response output)
tylerl
  • 30,197
  • 13
  • 80
  • 113