tags:

views:

37

answers:

1

I have the following abstract Django models:

class Food(models.Model):
    name = models.CharField(max_length=100)

    class Meta:
        abstract = True

In one of my view, I created a bunch of Food model:

panino = Food(name='Panino')
poutine = Food(name='Poutine')

food = [panino, poutine]

From the above, I'm not saving the model and storing the Food model in a regular Python list. I want to store the above food models in a QuerySet object. How can I do that without storing any data to the database?

+3  A: 

There's no point in turning them into a QuerySet since the methods are generally only usable on data in a database. Keep it as a list and use them that way.

Ignacio Vazquez-Abrams
I wanted to sort the models by a specific column by using the QuerySet order_by, I guess I'll have to find other ways to achieve that.
Thierry Lam
`order_by()` *doesn't* sort the models; it adds an `ORDER BY` clause to the SQL. Use `list.sort()` with a `key` argument to sort them.
Ignacio Vazquez-Abrams