django

Django unittests: The model is already registered Error

Hi! I come across several problems while trying django unittests library. Something strange happens: I defined the test like this: from django.core import management from django.test import TestCase from django.test.client import Client from django.core import mail from django.test.utils import setup_test_environment from django.contr...

Checking for empty queryset in Django

What is the recommended idiom for checking whether a query returned any results? Example: orgs = Organisation.objects.filter(name__iexact = 'Fjuk inc') # If any results # Do this with the results without querying again. # Else, do something else... I suppose there are several different ways of checking this, but I'd like to know h...

Django: Simple rate limiting

Many of my views fetch external resources. I want to make sure that under heavy load I don't blow up the remote sites (and/or get banned). I only have 1 crawler so having a central lock will work fine. So the details: I want to allow at most 3 queries to a host per second, and have the rest block for a maximum of 15 seconds. How could ...

Querying django ManyToMany

I have got Foo <=> FooGroup <=> Bar relation, where <=> stands for ManyToMany field. How do I retrieve all the Foos for a specific Bar instance? ...

getting the user from a admin validation class

Hello, I am trying to control admin item entry where non-super user accounts can't save a ChannelStatus model input that has a date attribute which is older than 2 days. I need to get the user so that I can check if the request is a reqular or a super user but couldn't achieve this. I have already tried "request.user.is_superuser", "use...

django auto slug in model forms like prepopulated-fields in django admin.

is there a way to get the same results of using pre-populated fields in django's admin site for slug fields in a standard modelform ...

Date range headache

#model class Promotion(models.Model): name = models.CharField(max_length=200) start_date = models.DateTimeField() end_date = models.DateTimeField() #view def promo_search(request): ... results = Promotion.objects.filter(start_date__gte=start_date).filter(end_date__lte=end_date) ... (The code above obviously is...

AN error about "User.add_to_class" to extend my user?I do not know why.

In my models.py, I user these code to extent two fields: User.add_to_class('bio', models.TextField(blank=True)) User.add_to_class('about', models.TextField(blank=True)) But when I creat a User : user = User.objects.create_user(username=self.cleaned_data['username'], \ email=self.cleaned_data['email'],password=self.cleaned...

How to run django shell from Emacs?

I'd like to be able to run ./manage.py shell in an Emacs buffer, with all the nice stuff that you get from ipython, like magic commands and autocompletion. Ideally I would also like to be able evaluate code from a buffer to the django shell. Is this possible? ...

What are the different options for processing uploaded PDF files in a Django application?

Our Django application needs to do a few things with uploaded PDF files: Verify that the file is a PDF and isn't corrupted Check that the file isn't encrypted Count the number of pages We run into problems with one unfortunately popular application that's idea of an unencrypted PDF export is actually an encrypted PDF file, just with ...

non-consistent django error

I'm running django on Dreamhost right now with fastcgi, and I'm getting really weird behavior. First, the server runs Python 2.3. On my computer, I'm running 2.6 and all my source code works. When I put it on my host though, nothing works. Right now, when I pkill python and then load a page, the first error complains about a syntax err...

Default ordering for m2m items by intermediate model field in Django

Hi, I have an unusual problem. Let's consider such models (taken from django docs): class Person(models.Model): name = models.CharField(max_length=128) def __unicode__(self): return self.name class Group(models.Model): name = models.CharField(max_length=128) members = models.ManyToManyField(Person, through='Me...

UserProfile StackedInLine/TabularInLine redesigned

Hello everyone and thanks for reading. I have a simple problem that I want to get rid of and I have not seen examples where this is achieved yet although searching around the net for quite a while. I recently extended with UserProfile so my admin.py looks like this: from django.contrib import admin from django.contrib.auth.models impo...

Django - Losing Auth Session

Hello, I am with some trouble in Django... After login I am losing auth session for some pages. If I access "accounts/login/","accounts/logout/",""accounts/register/" the session always will be there, but if I access different page I cant access the user variable. This is strange because I am using the same "base.html" for all pages ...

easy way of installing python apps without using PYTHON path or muli symlink in site-package

Hi, I didn't want to install python modules using easy install, symlinks in site-packages or PYTHONPATH. So, I am trying something that I do wants system wide, then any application installation is done locally. Note, the root password is required only once here. First create a symblink of.../pythonX.Y/site-packages/mymodules -> /home/...

Django: How to create a leaderboard

Lets say I have around 1,000,000 users. I want to find out what position any given user is in, and which users are around him. A user can get a new achievement at any time, and if he could see his standing update, that would be wonderful. Honestly, every way I think of doing this would be horrendously expensive in time and/or memory. Id...

Django sitemap index example

Hi! I have following models relation: class Section(models.Model): section = models.CharField(max_length=200, unique=True) name = models.CharField(max_length=200, blank = True) class Article (models.Model): url = models.CharField(max_length = 30, unique=True) is_published = models.BooleanField() section = models...

Django template, how to make a dropdown box with the predefined value selected?

Hi all, I am trying to create a drop down list box with the selected value equal to a value passed from the template values, but with no success. Can anyone take a look and show me what I am doing wrong. <select name="movie"> {% for movie in movies %} {% ifequal movie.id selected_movie.id %} <option value="{{movie.k...

Require one of a set of fields in a form to be valid.

How do I make a Django form where the user can choose between several ways of providing the data, and I need one of them to be valid. Say that I have a user profile where the user can choose between profile picture as URL or a imagefile: class UserProfile(forms.Form): picture_url = forms.URLField() picture_file = forms.ImageFie...

reloading .mo files for all processes/threads in django without a restart

We are working on a .po file editor for translators. And the translators need to see the changes they are doing on the live website. We managed to reload the .mo files for the current process/thread. but not for every process/thread. Is there a possibility to accomplish this without bigger performance problems? ...