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

Ordering of Fields in Django Field #11

Open
thiagogalesi4e opened this issue Apr 7, 2014 · 3 comments
Open

Ordering of Fields in Django Field #11

thiagogalesi4e opened this issue Apr 7, 2014 · 3 comments
Labels
Topic:Django Issues related to Django integration Type:NewFeature

Comments

@thiagogalesi4e
Copy link

Hello

1 - Create a Django model containing a VersionField, and insert values with different versions

2 - Use an order_by clause ordering by the VersionField field

3 - The ordering is done as text, not as version numbers

One example of ordering (this is with reverse ordering): [Version('1.2.3'), Version('1.10.3'), Version('1.0.3')]

Regards

@rbarrois
Copy link
Owner

Hi,

I'm afraid this would be quite complex to achieve, as the ordering is performed on the database side, that doesn't know about semantic versioning...

This might become possible with future versions of Django, which will include better support for custom fields (e.g PostgreSQL-specific ones, where http://pgxn.org/dist/semver/doc/semver.html could be used).

In the meanwhile, you can use sorted(my_qs, key=lambda o: o.version).

@rbarrois rbarrois added Type:NewFeature Topic:Django Issues related to Django integration labels Feb 28, 2016
@captin411
Copy link

Could this be accomplished by 0 padding all components? ex:

1.12.0-alpha1 -> 0001.0012.0000-alpha1

@rbarrois
Copy link
Owner

rbarrois commented Jul 8, 2016

@captin411 this would require:

  • Either complex transforms on the DB side (computing the max length of each component, then padding all values)
  • Or storing values with an arbitrary wide padding

Another option might be to implement the semver rules within the database itself; for instance with https://github.com/theory/pg-semver / http://pgxn.org/dist/semver/doc/semver.html

I'd be happy to merge an (optional) feature using this or a similar library and custom PSQL lookups!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Topic:Django Issues related to Django integration Type:NewFeature
Projects
None yet
Development

No branches or pull requests

3 participants