Skip to content
This repository has been archived by the owner on Jul 9, 2020. It is now read-only.

Commit

Permalink
[admin] Show config UUID hex instead of str
Browse files Browse the repository at this point in the history
Searching the str version in the admin doesn't yeld
the expected result, therefore it's better to show
the hex version whenever possible
  • Loading branch information
nemesifier committed Jan 20, 2017
1 parent 0b64032 commit e0f284a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions django_netjsonconfig/base/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ class AbstractConfigAdmin(BaseConfigAdmin):
list_display = ['name', 'backend', 'status', 'last_ip', 'created', 'modified']
list_filter = ['backend', 'status', 'created']
search_fields = ['id', 'name', 'key', 'mac_address', 'last_ip']
readonly_fields = ['id', 'status', 'last_ip']
readonly_fields = ['id_hex', 'status', 'last_ip']
fields = ['name',
'backend',
'id',
'id_hex',
'key',
'mac_address',
'status',
Expand All @@ -227,15 +227,20 @@ class AbstractConfigAdmin(BaseConfigAdmin):
actions_on_bottom = True
save_on_top = True

def id_hex(self, obj):
return obj.pk.hex

id_hex.short_description = "UUID"

def _get_fields(self, fields, request, obj=None):
"""
removes "id" field in add view
"""
if obj:
return fields
new_fields = fields[:]
if 'id' in new_fields:
new_fields.remove('id')
if 'id_hex' in new_fields:
new_fields.remove('id_hex')
return new_fields

def get_fields(self, request, obj=None):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
django.jQuery(function($) {
var p = $('.field-id p'),
var p = $('.field-id_hex p'),
value = p.text();
p.html('<input readonly id="id_id" type="text" class="vTextField readonly" value="'+ value +'">');
var id = $('#id_id');
Expand Down

0 comments on commit e0f284a

Please sign in to comment.