Search
Categories
Tags
Tag : django
Displaying timezone-aware dates with Tastypie
Written by on March 16, 2013 in Django, Python, Tastypie
Tags: date, django, tastypie, timezone, timezone-aware
So you have made the decision to use timezone-aware dates and now you are building your cool REST API using Tastypie. Of course timezones are important to your application, so you want to expose them when Tastypie exposes dates in the API.
You have a very simple resource that exposes a Django model that has an attribute, for example:
from django.db import models
class Entry(models.Model):
created = models.DateTimeField(auto_now_add=True)
# ... more fieldsfrom tastypie.resources import ModelResource
from myapp.models import Entry
class EntryResource(ModelResource):
class Meta:
queryset = Entry.objects.all()
Out of the box, you notice ...
Read more »
A Django Administration interface for non staff users
Written by on June 18, 2012 in Django, Python
Tags: django, django admin, Python
A while back I had a Django application in which I needed registered users able to view, create, update and delete objects in my system. These objects were instances of only a subset of all the Django models.Model subclasses I had defined in the models.py file of my application.
You may find this problem very similar to what the Django Admin site solves for administrators: you register some models that are displayed, and then the admins can create/update/delete the objects in the system as needed. Cool, lets use the Django admin! We should only call admin ...
Read more »
Django - Adding CAPTCHA validation to your forms
Written by on March 2, 2012 in Django, Python
Tags: CAPTCHA, django, password reset
Recently we implemented a "Forgot your password?" feature in one of our django sites and wanted to protect the mechanism so our users wouldn't get spammy messages from our servers. As much as we may hate it, forms in our sites usually act as spambots magnets. We need some kind of protection and CAPTCHAs usually do a good job.
There are cool tutorials like this one that can help you integrate django-auth views for password reset in your site. In his post we discuss how to add CAPTCHA protection to this mechanism. Our service of choice is reCAPTCHA because ...
Read more »
Get user data using django-social-auth
Written by on Feb. 13, 2012 in Django, Python
Tags: authorization, django, django-social-auth, facebook, Python, twitter
Recently we had to add support for social networks login to an application we are developing and we chose django-social-auth to work with. It is a well documented and easy to use django application for authentication.
But we wanted to do more than just authenticating the user, we wanted to get extra data like the profile picture, gender, etc. Fortunately django-social-auth has an useful pipeline that you can expand to fulfill this kind of tasks. I will explain briefly how to achieve this. I will assume you already have authentication working which is very well explained in the documentation.
First ...
Read more »
Django - Migrating from MySQL to PostgreSQL
Written by on Feb. 10, 2012 in DDBB, Django, Linux
Tags: django, MySQL, PostgreSQL

We recently had the need to move one of our Django app's back-end from MySQL to PostgreSQL. We wanted to try some of PgSQL's features in that particular context, and so far, we are quite pleased! Unfortunately the migration process was not as painless as we would have liked. At least, not until we found Philip Southam's cool py-mysql2pgsql tool.
Being an improved port of Max Lapshin's ruby-written mysql2pgsql, py-mysql2pgsql allows you to connect to a MySQL database and dump it's contents into a PostgreSQL compatible dump file or directly pipe it into and already ...
Read more »
Uploading an image using Django and saving it into an OS file
Written by on March 17, 2011 in Django
Tags: django, InMemoryUploadedFile

Uploading images using Django is pretty straightforward if you're using an ImageField tied to a model, but what happens if you're not working with the Django ORM, and you want to save the file directly to the OS? You'll have to deal with an "InMemoryUploadedFile" object.
Show me some code dude!
First, a simple html template to upload a file:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Upload image Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<h1>Upload image</h1>
{% if form.errors %}
<p style="color ...
Read more »





