Quentin Donnellan
Quentin Donnellan

Reputation: 2832

best way to add logic around django version?

With the new django.apps in Django 1.7, I'm now encountering a situation where the Django version will trigger the way an __init__ file handles configuration. For example:

from django.apps import AppConfig
...

Will not work on 1.6 and below. So it would be useful to check the version. My question: what's the canonical way for checking the version of Django?

String comparison? (this just seems funky)

if django.get_version() >= '1.7.0'

Or accessing the version tuple?

major_version == django.VERSION[0]
minor_version == django.VERSION[1]
if major_version >= 1 and minor_version >= 7

Obviously, the second method would fail on 2.0, and we could just say meh... I'll cross that bridge when I get there, but that certainly does not seem elegant.

Is there a third option? Thanks in advance!

Upvotes: 2

Views: 85

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799082

Sequences in Python are compared naturally.

>>> (2, 0, 0) > (1, 7)
True
>>> (1, 6) > (1, 7)
False
>>> (1, 6, 2) > (1, 7)
False

Upvotes: 5

Related Questions