introduce item.short_id + lookup by short id
This commit is contained in:
parent
d313274615
commit
7ac99dd44b
|
@ -63,6 +63,10 @@ class Item(models.Model, TreeModelMixin):
|
|||
|
||||
objects = hstore.HStoreManager()
|
||||
|
||||
def short_id(self):
|
||||
# let's just hope we never have 4 294 967 296 things :)
|
||||
return str(self.pk)[:8] # collisions? what collisions?
|
||||
|
||||
def __str__(self):
|
||||
return '- ' * (self.get_level() or 0) + self.name
|
||||
|
||||
|
|
|
@ -98,8 +98,16 @@ def item_display(request, pk):
|
|||
|
||||
|
||||
def label_lookup(request, pk):
|
||||
label = get_object_or_404(Label, pk=pk)
|
||||
return redirect(label.item)
|
||||
try:
|
||||
label = Label.objects.get(pk=pk)
|
||||
return redirect(label.item)
|
||||
except Label.DoesNotExist:
|
||||
try:
|
||||
# look up by short id
|
||||
item = Item.objects.get(uuid__startswith=pk)
|
||||
return redirect(item)
|
||||
except Item.DoesNotExist:
|
||||
raise Http404("Very sad to say, I could not find this thing")
|
||||
|
||||
|
||||
@login_required
|
||||
|
|
Loading…
Reference in New Issue