Django: how to create PDF, MS Word and Excel documents from templates

Posted on Mon 11 July 2016 in Programming • Tagged with django, python, libreoffice, pylokit, templates, documentsLeave a comment

If you’re building a Django system that implies serving some kind of documents like reports or bills, chances are you want to provide docs in various formats from PDF to MS Word to HTML. But how to implement this without resorting to numerous templates and packages for each document type?

Continue reading

Why you should use the Django admin: 9 tips

Posted on Wed 09 December 2015 in Programming • Tagged with django, python, adminLeave a comment

This writing is inspired by a comment on Reddit concerning my recent post:

The problem is that everyone I speak to seems to think the opposite - that the admin is super-limited, inflexible and hard to customize.”

andybak on Reddit

I’m about to break this prejudice right now. The Django admin is a really brilliant piece of software, which can significantly speed up your development.

Here are some tips about the Django admin, which I’ve found to be quite useful.

Continue reading

Managed search and replace in many files using Vim and ag.

Posted on Mon 16 November 2015 in Programming • Tagged with vim, agLeave a comment

Recently I faced an interesting problem. I had to search for the redundant lines of code (about a hundred occurences), and replace some of them. The bad thing is that I couldn’t do that automatically, as each case had to be manually reviewed.

So, how to automate this task, while keeping the manual control?

Continue reading

How to send Jabber (XMPP) messages from Django

Posted on Wed 11 November 2015 in Programming • Tagged with django, python, jabber, xmppLeave a comment

Did you ever want to have a simple Django notification bot? An intranet one which just sends you (or someone you tell it to) Jabber messages when certain events occur? So did I. Please, welcome: django-jabber.

Continue reading

Tip: How to get a single object`s value with Django ORM

Posted on Wed 11 November 2015 in Programming • Tagged with django, python, ormLeave a comment

There are times when you want to get a single field of a single object in the database. For example, just get the headline of the blog post #1, not fetching it’s body. How do you do it in a usual way?

>>> BlogPost.objects.only('headline').get(pk=1).headline
'Hello world'

# Or maybe even this way:
>>> BlogPost.objects.values('headline').filter(pk=1)[0]['headline']
'Hello world'

Recently I’ve stumbled upon a shorter one:

Continue reading

When you shouldn’t use the Django admin

Posted on Wed 11 November 2015 in Programming • Tagged with django, python, adminLeave a comment

In case you’ve thought I detest django.contrib.admin — by no means. Actually it’s one of the Django’s greatest features, I really love it. In most cases.

Here’s a real life story. We’ve had to quickly put up the first version of an intranet claim tracking system, and one of our developers was just crazy about the Django admin… So why not, we’ve got along with the stock interface as the primary one for ...

Continue reading