Skip to content

Commit d74071d

Browse files
committed
fixes minor bug in VersionField, add django-import-export due saxix#13
1 parent 50903d1 commit d74071d

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

concurrency/fields.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ def __init__(self, **kwargs):
3131
def get_default(self):
3232
return 0
3333

34+
def to_python(self, value):
35+
return int(value)
36+
3437
def validate(self, value, model_instance):
3538
pass
3639

@@ -63,8 +66,8 @@ def get_internal_type(self):
6366
return "BigIntegerField"
6467

6568
def pre_save(self, model_instance, add):
66-
old_value = getattr(model_instance, self.attname) or 0
67-
value = max(old_value + 1, (int(time.time() * 1000000) - OFFSET))
69+
old_value = getattr(model_instance, self.attname, 0)
70+
value = max(int(old_value )+ 1, (int(time.time() * 1000000) - OFFSET))
6871
setattr(model_instance, self.attname, value)
6972
return value
7073

@@ -80,7 +83,7 @@ def get_internal_type(self):
8083
return "BigIntegerField"
8184

8285
def pre_save(self, model_instance, add):
83-
value = (getattr(model_instance, self.attname) or 0) + 1
86+
value = int(getattr(model_instance, self.attname, 0)) + 1
8487
setattr(model_instance, self.attname, value)
8588
return value
8689

demo/demoproject/demoapp/admin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
from import_export.admin import ImportExportMixin
12
from concurrency.admin import ConcurrentModelAdmin
23

34

4-
class DemoModelAdmin(ConcurrentModelAdmin):
5+
class DemoModelAdmin(ImportExportMixin, ConcurrentModelAdmin):
56
# list_display = [f.name for f in DemoModel._meta.fields]
67
list_display = ('id', 'char', 'integer')
78
list_display_links = ('id', )

demo/demoproject/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
'django.contrib.staticfiles',
1717
'django.contrib.admin',
1818
'concurrency',
19+
'import_export',
1920
# 'demoproject.demoapp'
2021
)
2122

requirements.pip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ mock
33
webtest
44
django-webtest
55
selenium
6+
django-import-export

0 commit comments

Comments
 (0)