django

Django forms: custom error list format

New to python and django. Using the forms module and going through the errors one by one (so not just dumping them at the top) I noticed this solution to be able to set a custom format for errors, in my case, it'd be: <dd class="error">errstr</dd> And more or less copying the example provided, I have the following: forms.py ( I expan...

Getting a list of errors in a Django form

I'm trying to create a form in Django. That works and all, but I want all the errors to be at the top of the form, not next to each field that has the error. I tried looping over form.errors, but it only showed the name of the field that had an error, not an error message such as "Name is required." This is pretty much what I'd like to ...

Django template file extension preference

This Django ticket says that they will not add a default Django template file extension. What file extension do you use? ...

Test for existence of template block in a template

I have a structure where there's normally a page heading in (% block heading %} in my base template: base.html <h2>{% block heading %}{% endblock %}</h2> Most of the time, I'll pass in a heading like this through templates that extend base: extends-base.html {% block heading %}Super Cool Page!{% endblock %} However, for a special...

Testing Django model choices in templates

Say I have a model like: from django.db import models USER_TYPE_CHOICES = ( (1, 'Free'), (2, 'Paid'), ) class Account(models.Model): name = models.CharField(max_length=20) user_type = models.IntegerField(default=1, choices=TYPE_CHOICES) and in a template I want to test the user_type to show a special section if the u...

Pre-Filling a ForeignKey from a link to the Admin?

Some introduction. I have a "planet-like" feed aggregator with an extra layer on top. That extra layer allows for comments and elaboration on the aggregated posts. Here's some code for reference. class Post(models.Model): title = models.CharField() published = models.DateTimeField() class Story(models.Model): title = models...

how to modularize django settings.py?

When you install a new django application, you have to add/modify your settings.py module. For a project I'm trying to make that module a python subpackage and create a module for each application: settings\ __init__.py base.py admin.py feincms.py ... The problem I'm confronted with is how to merge settings.py att...

How to mock users and requests in django

I have django code that interacts with request objects or user objects. For instance something like: foo_model_instance = models.get_or_create_foo_from_user(request.user) If you were going to test with the django python shell or in a unittest, what would you pass in there? Here simply a User object will do, but the need for a mock req...

How do you trace 500 server errors with Apache + mod_python + Django?

I'm randomly getting 500 server errors and trying to diagnose the problem. The setup is: Apache + mod_python + Django My 500.html page is being served by Django, but I have no clue what is causing the error. My Apache access.log and error.log files don't contain any valuable debugging info, besides showing the request returned a 500....

How to do related questions autopopulate

I want to get a related [things/questions] in my app, similar to what StackOverflow does, when you tab out of the Title field. I can think of only one way to do it, which i think might be fast enough Do a search for the title in corpus of titles of all [things], and return first x matches. We can use whatever search is being used for ...

Appropriateness of a Django Textfield in a Model

Hello everyone, I have a field in a model that I want users to feel like they can write an arbitrary amount of text in. Django provides a CharField and a TextField in the models. I assume that the difference is that one of them is a char(max_length) and the other is a varchar internally. I am tempted to use the TextField, but since it ...

django jquery autocomplete - how to - django snippet 233 - handling foreign keys with a lot of values in forms

Hi, I found a nice snippet which seems to be a pretty nice and generic way to get autocomplete to your widgets using jquery autocomplete: link http://www.djangosnippets.org/snippets/233/ Unfortunately I did not found a complete example implementing this snippet and it seems that I do not understand it in detail to be able to implement...

Middleware Authentication

I have a DJANGO application divide in two sites(A middleware called site A and a front end called site B) and I need to share authentication between them. The site A is called by B to send username and password. Then A return an HTTP response to B and use HTTPResponseRedirect('/welcome') to redirect in a local function (protected by @l...

What is the canonical way to find out if a Django model is saved to db?

I generally check if obj.pk to knwo if the objects is saved. This wont work however, if you have primary_key = True set on some fields. Eg I set user = models.OneToOneField(User, primary_key=True) on my UserProfile. What is the canonical way to find out if a Django model is saved to db? ...

Django test runner not finding tests

I am a new to both Python and Django and I'm learning by creating a diet management site but I've been complete defeated by getting my unit tests to run. All the docs and blogs I've found say that as long as it's discoverable from tests.py, tests.py is in the same folder as models.py and you test class subclasses TestCase it should all ...

How to create Form from a Model which has a ListProperty

I am currently using Django forms with the Google App Engine and I have a model which is as follows: class Menu(db.Model): name = db.StringProperty(required=True) is_special = db.BooleanProperty() menu_items = db.ListProperty(MenuItem) I have a MenuForm which is the following: class MenuForm(djangoforms.ModelForm): c...

Komodo Edit 5.2 Django Template Syntax Error - Info: <head> previously mentioned

I am using Komodo Edit 5.2 for editing html and Django template files. It always shows a single syntax error inside the first {% block %} area on the first tag of my template. For example: {% extends "base.html" %} {% load i18n %} {% block title %}Hello{% endblock %} {% block content %} <p>Hello</p> <-- Syntax error on this singl...

jquery.autocomplete.js - how does autocomplete work?

Hi, I call the autocomplete jquery with the result of a GET request. The autocomplete function call looks like this: $('#id_project_owner_externally').autocomplete('/pm/contact_autocomplete'); The url /pm/contact_autocomplete returns a list of tuples. The first part of the tuple is the name of the contact and the second part of the ...

How to get module variable in function from another module?

I'd like to define a helper function that has the ability to modify a module-level variable (with known name) from surrounding context without explicitly passing it, e.g. # mod1.py mod_var = 1 modify_var() # mod_var modified print mod_var The problem is - I can't reference variable by mod1.mod_var, because I want to use helper functio...

Handling an "Inventory" (complex associations) with django + appengine

I'm writing a web application to manage a "game". Here are the models: class Character(db.Model): # Bio name = db.StringProperty() player = db.StringProperty() level = db.IntegerProperty() class Item(db.Model): name = db.StringProperty() description = db.StringProperty() value = db.StringProperty() class In...