Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In meta ,how to set "order by synax" #730

Closed
rfyiamcool opened this issue Oct 18, 2015 · 2 comments
Closed

In meta ,how to set "order by synax" #730

rfyiamcool opened this issue Oct 18, 2015 · 2 comments

Comments

@rfyiamcool
Copy link

I'm use Peewee ORM.

I have a class such as this:

class Sample(PMBaseModel):
    id = peewee.PrimaryKeyField()
    location = peewee.CharField(max_length=255)
    position = peewee.IntegerField()

    class Meta:
        db_table = 'sample'

how i can use Meta Class for set default ordering and define Order type?

@coleifer
Copy link
Owner

Well, I think setting a default ordering is always a bad idea, but since you asked:

class Meta:
    order_by = ('location', '-position')

order_by is a tuple. The elements of the tuple are field names. If prefixed by a "-", then the field is ordered descending.

@coleifer
Copy link
Owner

6969201 contains doc updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants