uuid is used when you need unique values from a model e.q (twitter with their status id)
in the models.py
in urls.py
and from views.py
in the models.py
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
#if you dont want to use the uuid as the model id use
#unique_id = models.UUIDField(default=uuid.uuid4, editable = False,unique=True)
in urls.py
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^status/$', views.status, name='status'),
]
and from views.py
from django.shortcuts import render
def status(request, uuid):
status = get_object_or_404(id=uuid)
return render(request, 'core/status.html', {'status': status})
Comments
Post a Comment