django

django - how can I access the form field from inside a custom widget

The below class inherits from the Textarea widget and features javascript code that displays how many characters more a user can enter in a textarea. class TextAreaWithCharCounter(forms.Textarea): class Media: js = ('js/jquery.charcounter.js',) def render(self, name, value, attrs = None): id = attrs['id'] ...

Filter ManyToMany box in Django Admin

I have a object with a many-to-many relation with another object. In the Django Admin this results in a very long list in a multiple select box. I'd like to filter the ManyToMany relation so I only fetch Categories that is available in the City that the Customer have selected. Is this possible? Will I have to create a widget for it? An...

How to dynamically provide lookup field name in Django query?

I want to look for a certain string in several fields of a Model in Django. Ideally, it would go something similar to: keyword = 'keyword' fields = ['foo', 'bar', 'baz'] results = [] for field in fields: lookup = "%s__contains" results.append(Item.objects.filter(lookup=keyword)) Of course this won't work, as "lookup" can't be ...

Two parter: Django book recommendation + Django real world advice

First question: What is your favorite Django book or online learning material? CodeProject examples + Django documentation, O'Reilly, etc. Second Question: What are some good tips and advice you have picked up along the way which helps you to use Django more effectively? Certain design patterns, language idioms, frameworks which tie ...

Can't switch language environment in Django

I have file locale/es/LC_MESSAGES/django.mo (and .po), ran makemessages and compilemessages. Definitely all messages are translated in settings.py have: USE_I18N = True LANGUAGE_CODE = 'es' Still django stubbornly takes strings from the english .po file... Why can that be? There must be some gotcha... Thanks. EDIT this appears to b...

Is splitting a large django app a good practice?

Hi SO, I have created a complex E-R diagram for a django site I'm developing. It maps to 11 tables in the database. The site has many features, so I would like to split it into multiple apps. The Django manual said that Django apps should be pluggable, but if I split the models into many apps, they would be dependant on each other. Is t...

Does Django have a built in way of getting the last app url the current user visited?

I was hoping that Django had a built in way of getting the last url that was visited in the app itself. As I write this I realize that there are some complications in doing something like that (excluding pages that redirect, for example) but i thought I'd give it a shot. if there isn't a built-in for this, what strategy would you use...

Django: models last mod date and mod count

I have a django model called Blog. I'd like to add a field to my current model that is for last_modified_date. I know how to set a default value, but I would like somehow for it to get automatically updated anytime I modify the blog entry via the admin interface. Is there some way to force this value to the current time on each adm...

how to overwrite User model

I don't like models.User, but I like Admin view, and I will keep admin view in my application. How to overwirte models.User ? Make it just look like following: from django.contrib.auth.models import User class ShugeUser(User) username = EmailField(uniqute=True, verbose_name='EMail as your username', ...) email = CharField(...

Django - Following a foriegn key relationship (i.e JOIN in SQL)

Busy playing with django, but one thing seems to be tripping me up is following a foreign key relationship. Now, I have a ton of experience in writing SQL, so i could prob. return the result if the ORM was not there. Basically this is the SQL query i want returned Select table1.id table1.text table1.user table2.user_name tab...

"Upload" a file from django shell

I need to import some data from a excel file and a folder with images, every row in the excel describes every entry and have a list of filenames in the folder (photos related to the entry). I've done a script which creates every entry in the database and saves it trough the django shell, but i have no idea how to instantiate a InMemoryU...

view only user group for django admin panel

Greetings I am trying to find a way to implement "view only user group" for selected models at the django admin site. In details, when a selected user of a group logs in, he/she can only browse and see allowed model entries. Thanks ...

Could not import Django settings into Google App Engine

Hello all you Google App Engine experts, I have used Django a little before but am new to Google App Engine and am trying to use it's development web server with Django for the first time. I don't know if this is relevent but I previously had Django 1.1 and Python 2.6 on my Windows XP and even though I have uninstalled Python 2.6 ...

What is the variable that indicates the environment in Django?

In Rails, there's an environments variable called RAILS_ENV that tells you which environment you're in. Other than creating my own environment variable, is there a default one that tells you which environment you are in in Django? ...

Installing Pinax on Windows

Can I install Pinax on Windows Environment? Is there a easy way? Which environment do you recommend? ...

Django ManyToMany Template Questions

Good Morning All, I've been a PHP programmer for quite some time, but I've felt the need to move more towards the Python direction and what's better than playing around with Django. While in the process, I'm come to a stopping point where I know there is an easy solution, but I'm just missing it - How do I display manytomany relationsh...

How long do zipimported module imports remain cached in memory when using appengine / python and is there a way to keep them in memory?

I've recently uploaded an app that uses django appengine patch and currently have a cron job that runs every two minutes. On each invocation of the worker url it consumes quite a bit of resources /worker_url 200 7633ms 34275cpu_ms 28116api_ms That is because on each invocation it does a cold zipimport of all the libraries django etc...

Django File Upload Handler Errors

In Django, I want to stop any file uploads that don't end in my designated extension as soon as they're received. To do this, I define a custom Upload Handler and write new_file to look something like this: def new_file(self, field_name, file_name, content_type, content_length, charset=None): basename, extension = os.path.splitext(file...

Django admin crashes after Save and Continue redirects to None instead of id of the primary key. Help?

I installed Django for the first time yesterday and trying it out in earnest today. I'm only planning to use it for the beautiful admin interface, Zend Framework for the rest. I imported an existing table event into the admin. There's no join needed. But the primary key is not 'id' it's called "event" (following this naming convention)....

new django app's from 1.1 causing 500 error

i'm running on wsgi on centos 5... i've recently updated locally from 1.0 to 1.1 I updated the server using svn update now when I apply a new app developed locally to the server it returns with a 500 error. all i'm doing is python manage.py startapp appname adding the app into installed_apps in the settings file and uploading thi...