django

How do I create a Django queryset equivalent to a SQL query using the OR operator?

In Django, I know using filter with multiple arguments gets translated into SQL AND clauses. From the Django Book: You can pass multiple arguments into filter() to narrow down things further: >>> Publisher.objects.filter(country="U.S.A.", state_province="CA") [<Publisher: Apress>] Those multiple arguments get translated ...

Should my python web app use unicode for all strings?

I see some frameworks like Django using unicode all over the place so it seems like it might be a good idea. On the other hand, it seems like a big pain to have all these extra 'u's floating around everywhere. What will be a problem if I don't do this? Are there any issues that will come up if I do do this? I'm using Pylons right no...

how to create a tariff calculator in django?

basically i'm creating a tariff calculator for a utility company in my country, based on a progressive rates table, an example given below 2.(a) In any one month for less than 1,001 gallons a fee of ………………………..… $9.23 (b) Proportionate fee for every gallon thereafter up to 2,000 gallons inclusive at the rate per 1,000 gallons of ………………...

How to measure Django cache performance?

I have a rather small (ca. 4.5k pageviews a day) website running on Django, with PostgreSQL 8.3 as the db. I am using the database as both the cache and the sesssion backend. I've heard a lot of good things about using Memcached for this purpose, and I would definitely like to give it a try. However, I would like to know exactly what w...

Django: custom constructor for form class, trouble with accessing data from request.POST.

Hello. I have written custom constructor for a form, the whole form class looks like this: class UploadForm(forms.Form): file = forms.FileField(label = "Plik") def __init__(self, coto, naglowek, *args, **kwargs): super(UploadForm, self).__init__(*args, **kwargs) self.coto = coto self.naglowek = naglowek...

Django contenttype question

I have a issue linking content type. I'm trying to pull a title out from this model class TankProfile(models.Model): user = models.ForeignKey(User) title = models.CharField(max_length=100) tank_type = models.SmallIntegerField(max_length=1, choices=TANK_TYPE, db_index=True, default=1, verbose_name="Tank Type") ts = models...

Tune queryset.get for working without DoesNotExist exception in model's Manager

I have for two similar models with one common Manager, that returns queryset for current logged user. I want User_Places.current_user.get(place=XXX) returns existing User_Place() object or empty User_Places(), when DoesNotExist exception raised. How is it possible? CurrentUserManager doesn't know anything about User_Places and User_Proje...

A production ready server to serve django on win32

I'd like to serve django application on windows XP/Vista. The application is an at hoc web interface to a windows program so it won't be put under heavy load (around 100 requests per second). Do you know any small servers that can be easily deployed on windows to serve a django app? (IIS is not an option as the app should work on all ve...

When is it appropriate to use Django context processors?

If about half of my views require the same data set, is it appropriate to use a context processor to make the data always available, or is there a better way to avoid repeating the code to get that data across several views without querying the data if it won't be used in the view? ...

ModelForms in Django where the underlying model depends on another model (via OneToOneField)

I have two models in my Django application, for the purposes of storing search parameters used for some homology search programs: # models.py class Search(models.Model): """A class to represent search runs.""" program = models.CharField(max_length=20) results_file = models.FileField( upload_to=(SEARCH_RESULTS_DIR) ...

using django, how to create method in model to return query data

In the following code, I'm tyring to create the method show_pro that will show all Arguments for the Case that are pro. I am getting this error: >>> Case.objects.all()[0].show_pro() Traceback (most recent call last): File "<console>", line 1, in <module> File "/home/john/mysite/../mysite/cases/models.py", line 23, in show_pro ...

Scaffold or django-admin without Auth app

I created my own Auth app, and now Admin is not working, what can you suggest? Exception now is: 'User' object has no attribute 'is_authenticated' I know my User really have no such method. So I have 2 ways: - change admin - adapt my user system My question was: is there possibility to easily off admin bound to auth ...

How to set up Python in a web server?

Not exactly about programming, but I need help with this. I'm running a development sever with WampServer. I want to install Python (because I prefer to use Python over PHP), but it seems there isn't an obvious choice. I've read about mod_python and WSGI, and about how the latter is better. However, from what I gathered (I may be wrong...

What Built-in Form Validation Does App Engine/Django Have?

I'm writing an app using App Engine and Django. What Built-in Form Validation Does App Engine/Django Have? For example how can I verify that the user actually entered an integer and not a string? ...

Need help for developing facebook app

hi, I am trying to develop facebook app using django. The problem I am facing is how to use facebook api and get user friend list. view.py def canvas(request): # Get the User object user, created = FacebookUser.objects.get_or_create(id = request.facebook.uid) return direct_to_template(request, 'canvas.fbml', extra_context...

Make Django return response as a "different filename"

I have a Django view which returns an HttpResponse with a special MIME type to make the user's browser "download" the file instead of view it in the browser. The problem is that the default filename that the response will be saved as is the URL which the user tried to access. Is there any way to include a default filename in the HttpRe...

Django theme/skin repository

Is there some place of freely available themes/skins for standard Django apps? I mean the typical stuff containing footer, header, etc. ...

ModelMultipleChoiceField validation acting differently depending on widget

I have a form with a ModelMultipleChoiceField and it works like a charm. However, when I set widget=forms.RadioSelect the form validation always fails with the error message "Enter a list of values." As I said, it works perfectly well with the default widget, but not with the radio select widget. The POST request to validate the form ...

Django validation array of errors

I am using rf['email'].errors As said in docs, I can use it to have array of errors. [str(e) for e in rf['email'].errors] #give me ["<django.utils.functional.__proxy__>"] If repr or str - it gives ul's or string of array. So it worked only when I used repr and eval together. But I think its stupid solution. eval(`rf['email'].e...

django-cms, django flatpages, tiny mce not displaying

Hello, I've implemented both django-cms and flatpages, but can not get tiny_mce to display in either. urls.py (r'^tinymce/', include('tinymce.urls')), from django.conf import settings if settings.DEBUG: urlpatterns += patterns('', (r'^site_media/(?P<path>.*)$', 'django.views.static.serve', {'document_root'...