0

in the models.py, I have a model which has a list attribute:

Class Controller(models.Model):
    def controller(self):
        result = []
        #...do some works here...
        result = xxx

Now I want to use the "result" attribute in the template, in views.py I have:

def results(request):
    cmodel = Controller()
    cmodel.controller()
    firstList = get_list_or_404(Controller, 'I am not sure how to write this filter')
    return render_to_response('blablabla/')

I am not sure how to write the filter, since the samples are giving something like "pk=1", but I don't have any primary keys or ids for the 'result' object. Can anyone help me? Thank you.

4

1 回答 1

0

你的controller函数应该返回result

Class Controller(models.Model):
    def controller(self):
        result = []
        #...do some works here...
        result = xxx
        return result # <----------

然后你可以得到它:

c = Controller()
result_list = c.controller()

那是你要的吗?

于 2013-07-12T21:16:53.257 回答