Accessing Request Object In Form

Posted: May 18th, 2010 | Author: | Filed under: Django | Tags: , , | 1 Comment »

Something that I use quite regularly is accessing the request object in a form.

It is actually pretty simple, in your form you add a custom __init__ function that sets the request as a parameter:

class PasswordRecoverForm(PasswordResetForm):
    def __init__(self, *args, **kwargs):
    self.request = kwargs.pop('request', None)
    super(PasswordRecoverForm, self).__init__(*args, **kwargs)
def clean_email(self):
    """Do something with the request"""
    print self.request

Then in your view code you can pass the request as a parameter.

form = PasswordRecoverForm(request=request)

Change Django Auth Group Ordering

Posted: May 17th, 2010 | Author: | Filed under: Django | Tags: , | No Comments »

Following on from my last post on changing the behaviour of the Django contrib auth models. Another thing you might like to do is to change the default ordering:

from django.contrib.auth.models import User
User._meta.ordering = ['-email']

or

from django.contrib.auth.models import Group
Group._meta.ordering = ['-id']

Django hosting

Posted: May 14th, 2010 | Author: | Filed under: Django | No Comments »

After a month of hard work we are proud to announce that our new django hosting service is up and running!

Django Hosting
The main features include :

  • Live logs
  • manage.py
  • Money back guanrantee
  • Django version switcher
  • Your own domain name
  • 500Mb file storage
  • 100Mb database storage
  • Import code from SVN or GIT

Django Foo hosting


Django paypal sandbox

Posted: May 14th, 2010 | Author: | Filed under: Django | Tags: | No Comments »

When using the django-paypal pluggable app there is not really a settings to specify if you want to interact with the sandbox or with the normal site.
To do this you need to call the the form like this

{{ form.sandbox }}

instead of

{{ form.render }}

Change Django Auth User Meta

Posted: April 29th, 2010 | Author: | Filed under: Django | Tags: , , | 4 Comments »

Sometimes it can be helpful to change the default behaviour of the Auth User model or other models built into Django.
One use case might be if you want to change the length of the username field in the Auth User model to allow for longer usernames (e.g. an email address).

There is a simple way to change the max length attribute:

from django.contrib.auth.models import User
User._meta.get_field_by_name('username')[0].max_length=75