django

Django template for loop

I have a basic question, in the Django template language how can you tell if you are at the last loop iteration for a "for loop"? ...

how to use a slug in django

I am trying to create a SlugField in Django. I created this simple model: from django.db import models class test(models.Model): q = models.CharField(max_length=30) s = models.SlugField() I then do this: >>> from mysite.books.models import test >>> t=test(q="aa a a a", s="b b b b") >>> t.s 'b b b b' >>> t.save() >>> t.s 'b ...

python random.random() causes "'module' object is not callable" when used in custom template tag

If I start python from the command line and type: import random print "Random: " + str(random.random()) It prints me a random number (Expected, excellent). If I include the above-two lines in my django application's models.py and start my django app with runserver I get the output on the command line showing me a random number (Grea...

How are write conflicts avoided in django administration?

Suppose there are two (or more) django administrators who have read a database record and then change and save it. There is no database problem, but some administrators are going to be surprised that the record they wrote was overwritten. Is this issue ever addressed? One way would be to have an explicit "edit in progress" button which ...

should I drop Google App Engine?

I am developing some kind of financial market simulation on GAE. Although I have attained much progress, I have begun to consider dismissing GAE and going for a Django + rdbms solution for the last few days. Let me state my reasons: transactions: GAE supports transactions with single entity groups. if an application involves complex tr...

'Answer' instance needs to have a primary key value before a many-to-many relationship can be used.

I have a model called Answer which has a ForeignKey relationship to another model called Question. This means there can be several answers to question, naturally. class Question(models.Model): kind = models.CharField(max_length=1, choices=_SURVEY_QUESTION_KINDS) text = models.CharField(max_length=256) class Answer(models.Model...

Looking for interesting and instructive python code (web programming)

I'm learning python and my current focus is on web programming. Thx to some help from stackoverflow, I recently made some reasonable progress. While still at basic level, I can now "somewhat" comfortably use html templates, web frameworks (haven't done anything significant yet), sqlite (no mySQL yet), etc. Before I start another proje...

Django -- ForeignKey() uses different column than the row ID?

Hi, I have an application called Location. Location has Country, State, City, Big_City_Nearby, Longitude, latitude. I have an application for an item for sell. Item has Title, Link, Description, Price & Location which is a ForeignKey(). Now, if someone wants to see all items for sell in the US, they click on a link (let say http://ex...

Should I create form objects or generate them from model

I recently found out that I can generate forms from models. I've read the docs and am wondering why someone would opt not to do this in favor creating their own form objects. ...

Django equivalent of COUNT with GROUP BY

I know Django 1.1 has some new aggregation methods. However I couldn't figure out equivalent of the following query: SELECT player_type, COUNT(*) FROM players GROUP BY player_type; Is it possible with Django 1.1's Model Query API or should I just use plain SQL? ...

Using Sql Server with Django in production

Has anybody got recent experience with deploying a Django application with an SQL Server database back end? Our workplace is heavily invested in SQL Server and will not support Django if there isn't a sufficiently developed back end for it. I'm aware of mssql.django-pyodbc and django-mssql as unofficially supported back ends. Both proje...

How can I use Django admin list and filterering in my own views?

I’m just beginning to learn Django and I like the automatic listing in Django admin and the way you can configure filters and what columns to show. Is it possible to use it in my own applications? I’ve looked in the source for the admin and figured out that I probably want to subclass the “ChangeList”-object in some way and use it in my...

HAProxy load balancer in front of Django instances

Hello, I'd like to have haproxy caching/redirect the /static/.+ url path of my django instances to speed up static file serving. What's the best way to do that? ...

Why is django giving error: no module named django.core?

I get the error in question when I attempt to create a project. I followed the instructions found at how to install python an django in windows vista. ...

A simple views question for django/jQuery calls

Hi, I'm trying to figure out how to pass html back to a jQuery call, but for some reason my code refuses to work. t = get_template('success.html') html = t.render(Context({'success': True})) # should render '<p><h1>aoeu</h1></p>' x = "{'success' : '" + html + "'}" return HttpResponse(x) jQuery code: $.post("adduser", data, functi...

Writing a __init__ function to be used in django model

Hi, I'm trying to write an init function for one of my models so that I can create an object by doing p = User('name','email') When I write the model, I have def __init__(self, name, email, house_id, password): models.Model.__init__(self) self.name = name self.email = email This works, and ...

FastCgi crashes -- Want to catch all exceptions but how?

Hi, I have a django app running on apache with fastcgi (uses Flup's WSGIServer). This gets setup via dispatch.fcgi, concatenated below: #!/usr/bin/python import sys, os sys.path.insert(0, os.path.realpath('/usr/local/django_src/django')) PROJECT_PATH=os.environ['PROJECT_PATH'] sys.path.insert(0, PROJECT_PATH) os.chdir(PROJECT_PAT...

What is the correct argument for ForeignKeyRawIdWidget?

I have an admin class which uses raw_id_fields. Instead of displaying the number key, I would like to convert that to the __unicode__ for the corresponding foreign key object. I thought a way to do this would be to add a form to the admin class. This form would be one in which the field I want to change is overridden with my own widget...

where to put method that works on a model

I'm working with Django. I have a model called Agrument. Arguments have sides and owners. I have a function that returns back the side of the most recent argument of a certain user. like obj.get_current_side(username) I've added this to the actual Argument model like this def get_current_side(self, user): return self.argu...

Django filter -- How do I go about filtering for emply or NULL names in a queryset

Hi, I have first_name, last_name & alias (optional) which I need to search for. So, I need a query to give me all the names that have an alias set. Only if I could do: Name.objects.filter(alias!="") So, what is the equivalent to the above? Thanks, VN44CA ...