django

Django: accessing session variables from within a template?

Hi all If I set a session variable in Django, like: request.session["name"] = "name" Is there a way I can access it from within a template, or do I have to retrieve it from within a view, and then pass it to a template? Asking because I have around 10 little session variables that I'd like to access within a template, and passing a...

Rate limiting Django admin login with Nginx to prevent dictionary attack

I'm looking into the various methods of rate limiting the Django admin login to prevent dictionary attacks. One solution is explained here: simonwillison.net/2009/Jan/7/ratelimitcache/ However, I would prefer to do the rate limiting at the web server side, using Nginx. Nginx's limit_req module does just that - allowing you to specify ...

Changing User ModelAdmin for Django admin

How do you override the admin model for Users? I thought this would work but it doesn't? class UserAdmin(admin.ModelAdmin): list_display = ('email', 'first_name', 'last_name') list_filter = ('is_staff', 'is_superuser') admin.site.register(User, UserAdmin) I'm not looking to override the template, just change the displayed fie...

Django JSON serializable error

With the following code below, There is an error saying File "/home/user/web_pro/info/views.py", line 184, in headerview, raise TypeError("%r is not JSON serializable" % (o,)) TypeError: <lastname: jerry> is not JSON serializable In the models code header(models.Model): firstname = models.ForeignKey(Firstname)...

Django newbie question: can't start a new project

Hello. I'm totally new to django, and I'm using its documentation to get help on how to use it but seems like something is missing. i installed django using setup.py install command and i added the ( django/bin ) to system path variable but. i still cant start a new project i use the following syntax to start a project : django-admin....

internationalisation in django

Hello , I am doing internationalisation in django admin.I am able to convert all my text to the specific langauge.But i m not able to change the 'app' name suppose django-admin.py startapp test this will create a app called test inside my project.Inside this app 'test' i can create many classes in my model.py file.But when i regist...

How to automatically accept comments from authenticated users in django.contrib.comments

Is there a way to make Django automatically set the is_public field of the comment as True. I only allow comments for registered users and would like to skip manual review of comments posted. ...

ForeignKey django 1.1.1 model

I have class staff_name(models.Model): firstname = models.CharField(max_length=150) surname = models.CharField(max_length=150) class inventory_transaction(models.Model): staffs = models.ForeignKey(staff_name) I want to get or create staff surname and first name through inventory_transaction I used these code below ...

Django: Getting a Python encoding error when handling HTTP response in Latin1?

I'm working in Django, and using urllib2 and simplejson to parse some information from an API. The problem is that the API returns information in the Latin-1 encoding, and just once in a while there's a character in there that causes Django to crash horribly with an encoding error. This is my code: get_person_id_url = "http://www.domai...

python list mysteriously getting set to something within my django/piston handler

To start, I'm very new to python, let alone Django and Piston. Note: (I've updated this since the first two suggestions... you can view the old post in txt form here: http://bennyland.com/old-2554127.txt). The update I made was to better understand what was going wrong - and now I at least sort of know what's happening but I have no cl...

Django automatically compress Model Field on save() and decompress when field is accessed

Given a Django model likeso: from django.db import models class MyModel(models.Model): textfield = models.TextField() How can one automatically compress textfield (e.g. with zlib) on save() and decompress it when the property textfield is accessed (i.e. not on load), with a workflow like this: m = MyModel() textfield = "Hello, ...

Django queryset to find a char value with filtered out spaces?

There are database string values that are sometimes stored with unnecessary spaces: "SDF@#$#@ 132423" Given the value without spaces in the UI of a program: "SDF@#$#@132423" How could I do a Django queryset filter to find the Database value (with spaces) from the UI input value sans spaces? ...

Sending emails from Django App

We are a growing Django app that is currently using Google Apps to send email. We are hitting the maximum limits of email sending and need a better solution. We prefer not to have to manage our own email servers and the easier the better. What is the best, easiest, and cheapest way to send a large amount of email? We have looked at Pos...

What could cause Django to start failing its own tests after an OS and Django reinstall?

I had to reinstall my OS, and so, I reinstalled django 1.1. Since reinstalling, when I run tests in my app, I get several failures from django.contrib.auth. Logs: http://dpaste.com/178153/ I asked on #django, and no one is too sure what the cause of the errors are. Some of my own code fails its tests, because it's not fully written yet...

How do I construct a Django form with model objects in a Select widget?

Let's say I'm using the Django Site model: class Site(models.Model): name = models.CharField(max_length=50) My Site values are (key, value): 1. Stackoverflow 2. Serverfault 3. Superuser I want to construct a form with an html select widget with the above values: <select> <option value="1">Stackoverflow</option> <option...

How to set variables in base template in django?

i have template base.html and some children templates. I don't know how to set variables for base.html for example if i have {% for u in users %}{% endfor %} where do I assign it to users? is there some parent view for all views? ...

When I run Django on Dreamhost using SQLite, why do I get an OperationalError telling me that a table doesn’t exist?

I had a Django site running on Dreamhost. Although I used SQLite when developing locally, I initially used MySQL on Dreamhost, because that’s what the wiki page said to do, and because if I’m using an ORM, I might as well take advantage of it by running against a different database. After a while, I switched the settings on the server t...

version control + continuous integration with Flex + Ruby or Django

trying to pick version control, continuous integration, and host for Flex + Ruby or Django smallish project. Question: version control: I've used SVN and CVS in the past. I hear great things about git. Not sure what to pick. continuous integration: I've heard good things about hudson and cruiseControl. Not sure what to pick hosting: is...

ProgrammingError when aggregating over an annotated & grouped Django ORM query

I'm trying to construct a query to get the "average, maximum and minimum number of items purchased per user". The data source is this simple sales records table: class SalesRecord(models.Model): id = models.IntegerField(primary_key=True) user_id = models.IntegerField() product_code = models.CharField() pr...

Why is it that I cannot insert this into Django correctly?

new_thing = MyTable(last_updated=datetime.datetime.now()) new_thing.save() >>>>select * from MyTable\G; last_updated: 2010-04-01 05:26:21 However, in my Python console...this is what it says... >>> print datetime.datetime.now() 2010-04-01 10:26:21.643041 So obviously it's off by 5 hours. By the way, the database uses "SYSTEM" as it...