Skip to main content

Tutorial 1 - How to Use uuid in Django

uuid is used when you need unique values from a model e.q (twitter with their status id)

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

Popular posts from this blog

QT Projects and Libraries for The C++ Programmer

Here i will gather the best and most interesting Qt/C++  projects and libraries  for your perusal https://github.com/biluna/biluna    Biluna is a Qt application framework. It started with the idea to make an Eclipse like (Java) framework. The framework allows the developer to start with a ready to use desktop application. The additional functionality is added by using plug-ins. The basic framework provides a MDI (multiple document interface) window work area with docking windows at the different sides of the working area.   https://github.com/openhomm/openhomm                                                        OpenHoMM is open source clone of 'Heroes Of Might And Magic III Shadow Of Death' game engine. Requirments: original game data Qt >= 5.5.1   https://github.com/shadowsocks/libQtShadow...

Python Snippet 01 - Requirements.txt

Recently i needed to get the requirements of my Django project so i could move it to a production server.  So i researched the web and found REQUIREMENTS.TXT Why requirements.txt? Any application typically has a set of dependencies that are required for that application to work. The requirements file is a way to specify and install specific set of package dependencies at once. Format for requirements file:  Django ==0.10.1 djangorestframework ==1.2.0 Method 1: $ pip freeze > requirements.txt Use pip’s freeze command to generate a requirements.txt file for your project: If you save this in requirements.txt, then you can $ pip install -r requirements.txt to install all the requirements of your project. NB: Use the pip freeze command in your virtualenv or else yuou will list all your dependencies