django - Object not showing in DetailView when using a uuid as primary key -
i'm using generate primary keys don't want them simple numbers easy guess (found in post):
def make_uuid(): return base64.b64encode(uuid.uuid4().bytes).replace('=', '')
here model:
class shipment(models.model): trackid = models.charfield(max_length=36, primary_key=true, default=make_uuid, editable=false)
how can make detailview view work when use url myapp.com/detail/trackid_goes_here? i've tried saw here , still can't make work.
also, there better way unique primary keys using uuid?
thanks!
update:
it shows template using in views.py:
class shipmentdetailview(detailview): template_name = 'shipments/detail.html' context_object_name = 'shipment' def get_object(self): model = shipment.objects.get(pk=self.kwargs['trackid'])
and urls.py:
url(r'app/detail/(?p<trackid>[\w\d-]+)/$', coreviews.shipmentdetailview.as_view(), name='shipment'),
but "tags" used on template ( {{ shipment.trackid }} ) not working...
the reason template tags not working because need return instance in get_object()
:
def get_object(self): return shipment.objects.get(pk=self.kwargs['trackid'])
if don't return anything, method returns none
(its default return value); , templates have nothing show.
Comments
Post a Comment