background preloader

Django

Facebook Twitter

Django patterns part 3: efficient generic relations | rosemanblog. I've previously talked about how to make reverse lookups more efficient using a simple dictionary trick. Today I want to write about how this can be extended to generic relations. At its heart, a generic relationship is defined by two elements: a foreign key to the ContentType table, to determine the type of the related object, and an ID field, to identify the specific object to link to. Django uses these two elements to provide a content_object pseudo-field which, to the user, works similarly to a real ForeignKey field. And, again just like a ForeignKey, Django can helpfully provide a reverse relationship from the linked model back to the generic one, although you do need to explicitly define this using generic.GenericRelation to make Django aware of it.

As usual, though, the real inefficiency arises when you are accessing reverse relationships for a whole lot of items - say, each item in a QuerySet. Install Django on Ubuntu Linux | Blog | GAE framework. Django Admin, FileField and __unicode__() | Odeon. The FileField or ImageField is used in many situations (for storing avatars, albums etc). Using it's details in the admin can result in high loading times if you add them in the model's __unicode__().

Simple Example Let's say you use for storing the avatar of your users (UserProfile has a FK to Avatar): class Avatar(IKImage): the_image = models.ImageField(upload_to='/your/path') In the admin you need to be able to differentiate between Avatars so you need a __unicode__() method. Ideally you need to show something related to the file and what else if not the url: def __unicode__(self, *args, **kwargs): return u'%s' % self.original_image.url For a few records, you will not notice any problem, but as your project grows, the loading time of admin Profile edit page will increase. Why does loading time increase? When getting the url of the file, django will acces the storage, which response time will always be slow. The fast way Use database fields to keep things smooth. DjangoResources. All snippets. Facebook oauth and Graph API with Django | Laurent Luce's Blog. In this post, I am going to describe how I integrated Facebook into Gourmious, so users could post their favorite dishes on Gourmious and on Facebook at the same time.

I wanted to keep the Gourmious login so the users could decide to login using their Gourmious credentials or using the Facebook login feature. I also wanted all users to have a Gourmious account so I didn’t allow users to login using their Facebook credentials if they didn’t have a Gourmious account. I decided to support the following 3 scenarios : - user has a Django account and he logs in with Facebook. I associate his Facebook account to his Django account. This needs to be done only once. - user does not have a Django account and tries to login using Facebook. I ask him first to create a Django account and I associate both accounts. - user logs in using his Django credentials. Facebook oauth is easier than the old Facebook connect. We are going to use the Django app django_facebook_oauth to make our life easier.

Django User Profiles - Simple yet powerful. So you're building a web application, and using the excellent contrib.auth subsystem to manage user accounts. Most probably you need to store additional information about your users, but how? Django profiles to the rescue! Django provides a lightweight way of defining a profile object linked to a given user.

The profile object can differ from project to project, and it can even handle different profiles for different sites served from the same database. In a nutshell, using Django profiles consists of 3 steps: Define a model that holds the profile information. Defining the user profile model The only requirement Django places on this model is that it have a unique ForeignKey to the User model, and is called user. For our example, we'll create 2 user profile fields (url and company). account/models.py from django.db import modelsfrom django.contrib.auth.models import User Tell Django about the profile object This is defined in the projects settings.py file. foo/views.py. Push service for creating real-time web apps using HTML5 WebSockets and Comet. Introducing django-lazysignup — Stereoplex.

Django-lazysignup is a Django application that was partly inspired by a talk that Simon Willison gave at EuroPython a few years back (perhaps 2008, or 2009?) And partly to scratch an itch I had with an application I was building at the time. The problem it tries to solve is that making users sign up with a web site just to try out your app is quite a high barrier - potential users just bounce right off that registration form. I'd seen some efforts to solve this problem before. Most seemed to involve stashing the data for some predetermined part of the website somewhere (often in the session) and then reconstituting it into real application data when the user eventually bites the bullet and signed up. This worked OK, but you had to write it anew for every web site, as clearly the data you'd want to store would change from site to site. You also ended up effectively developing a miniature version of your site that would work with some limited data set.

This didn't really seem good enough. Pennersr/django-allauth - GitHub. Django search results. Bienvenue. Ubernostrum / django-registration / wiki / Home – Bitbucket. Agiliq/Django-Socialauth at master - GitHub. Izi / django-admin-tools / wiki / Home – Bitbucket. Django-admin-tools is a collection of extensions/tools for the default django administration interface, it includes: a full featured and customizable dashboard; a customizable menu bar; tools to make admin theming easier. Please join the mailing list if you want to discuss of the future of django-admin-tools. If you find django-admin-tools useful, please consider giving a donation via paypal or just tip me if you're using Gittip, any contribution will be greatly appreciated.

List of people who already donated to the project Installation To install django-admin-tools, run the following command inside this directory: python setup.py install If you have the Python easy_install utility available, you can also type the following to download and install in one step: easy_install django-admin-tools Or if you're using pip: pip install django-admin-tools An installation guide is available in the documentation. Documentation Translations Screenshots The django admin login screen The admin index dashboard.

Django-filebrowser - File-Management with the Django Admin-Interface. ScaffoldScript.