Permissions in Django Admin

Admin dashboard is one of the Django’s useful feature. Admin dashboard allows super users to create, read, update, delete database objects. The super users have full control over the data. Staff user can login into admin dashboard but can’t access data. In few cases, staff users needs restricted access . Super user can access all data from various in built and third party apps. Here is a screenshot of Super user admin interface after login. [Read More]

Testing Django Views

Majority of web frameworks promote MVC/MTV software pattern. The way web applications are designed today aren’t same as 5-6 years back. Back then it was server side templates, HTML, API’s weren’t widespread and mobile apps were becoming popular. Rise of mobile and Single Page Application shifted majority of web development towards API centric development. Testing API is super simple with data in and data out, but testing a django view in classic web application is difficult since HTML is returned. [Read More]

Simple Json Response basic test between Flask and Django

Django and Flask are two well known Python web frameworks. There are lot of benchmarks claim Flask is 2xfaster for simple JSON Response, one such is Techempower. After lookinginto the source, it struckme Django can do better! I will compare Flask and Django for simple json response. The machine used is Macbook pro, Intel Core i5-4258U CPU @ 2.40GHz,with 8 GB Memory on OS X 10.10.3. gunicorn==19.3.0 will be used for serving WSGI application. [Read More]

django print exception to console

Django has very good debug toolbar for debugging SQL. While working with Single Page Application and API exceptions can’t be displayed in browser. Exception is sent to front end. What if the exception can be printed to console ? Django middleware gets called for every request/response. The small helper class looks like Add the filename and class name to MIDDLEWARE_CLASSES in settings file like This is how exceptions looks [Read More]

Two scoops of django

Two Scoops of Django -1.5 is book by Pydanny and Audrey Roy focusing on writing clean and better Django application. If you are using Django in production this is must read book. Q: I am using django since 0.8 do I need this book ? A: Yes, consider the book as starting point to validate your assumption. Q: I just started using django, should I read this ? A: Yes. I started to use django in production last month. [Read More]

Updating model instance attribute in django

It is very common to update single attribute of a model instance (say update first name in user profile) and save it to db. In [18]: u = User.objects.get(id=1) In [19]: u.first_name = u"kracekumar" In [20]: Very straight forward approach. How does django send the sql query to database ? In [22]: from django.db import connection In [22]: connection.queries Out[22]: [... {u'sql': u'UPDATE "auth_user" SET "password" = \'pbkdf2_sha256$12000$vsHWOlo1ZhZg$DrC46wq+a2jEtEzxmUEw4vQw8oV/rxEK7zVi30QLGF4=\', "last_login" = \'2014-02-01 06:55:44. [Read More]