django

How to manage timezones in a web application?

Hi, I wan't to manage the different timezones of my users in my web application, but I have no idea where to start. I have to save the local time of each user in my database?, or maybe make the conversion to a UTC time, save it, and then make the conversion again to show it?, or there is another way? For example, if one of my users make ...

Validating Uploaded Files in Django

A Django app that I am working has an Event model. An Event may have associated photos, static html files and pdf files. I would like to allow trusted users to upload these files, but I am wary about security, especially having read the following in the Django docs (link). Note that whenever you deal with uploaded files, you shoul...

Customize the html output of Django's form validation

Whenever you use a {{ form.field.errors }} tag in a Django template, the validation message that is displayed is always surrounded with a unordered list tag. This is not ideal for me. Am I able to modify the surrounding validation message html for a form from a reusable package? ...

how can I filter on the second element in a tuple of tuples?

In my model I have a field: country = models.CharField(_('Country'), max_length=2, choices=COUNTRIES) Where COUNTRIES is a tuple of tuples like this: COUNTRIES = ( ('AF', _('Afghanistan')), ... and so on Now I want to filter an instance of that model, by the country name. This: i = MyModel.objects.filter(country__iexac...

Checking for content in Django request.POST

I feel like such a n00b asking this question but it's late and I'm tired. ;) I am accepting data via request.POST like this: if request.method == 'POST': l = Location() data = l.getGeoPoints(request.POST) appid = settings.GOOGLE_API_KEY return render_to_response('map.html', ...

Help with manage.py syncdb

Hello there, I am a newbie learning Python/Django... Am using the following tutorial located at: http://bit.ly/eIdT Created a mysite database in MySQL 5 running on Snow Leopard. Edited the settings.py file to look like this: DATABASE_ENGINE = 'mysql' DATABASE_NAME = 'mysite' DATABASE_USER = 'root' ...

How can I get a variable passed into an included template in django

Hi, I am a Django newbie and am unable to achieve something trivial. Please help me with this. I am setting a variable pgurl in my views.py Am able to access the variable {{pgurl}} in my with_tag.html template. This template includes a pagination.html template into itself In pagination.html I am unable to use the variable {{pgurl}} an...

What is the cleanest way to add code to contrib.auth

I've migrated an old joomla installation over to django. The password hashes is an issue though. I had to modify the get_hexdigest in contrib.auth.models to have an extra if statement to reverse the way the hash is generated. # Custom for Joomla if algorithm == 'joomla': return md5_constructor(raw_password + salt).hexdigest() # Djan...

Getting data from an Excel sheet

How do I load data from an Excel sheet into my Django application? I'm using database PosgreSQL as the database. I want to do this programmatically. A client wants to load two different lists onto the website weekly and they don't want to do it in the admin section, they just want the lists loaded from an Excel sheet. Please help becaus...

Weird Time Issue in Python

Problem with using times in Python. Terminal > Python >>> calendar.timegm(datetime.datetime.now().utctimetuple()) 1258449380 This time indicates GMT: Tue, 17 Nov 2009 09:16:20 GMT Eclipse via Django Server >>> calendar.timegm(datetime.datetime.now().utctimetuple()) 1258427784 This time indicates GMT: Tue, 17 Nov 2009 03:16:24 GMT...

Scheduling Filter on Database with Time Interval

Let's you have a science experiment called Weather and it records general information about the weather, one of which is recording the humidity every minute. After say 10 hours, you'll have 600 database values stored. Weather.objects.filter().exclude(time__lt = commence).exclude(time__gt = cease) This would create a filter for the Wea...

select_related() and many to many fields with ajax (Django)

I have a simple view that I want to respond to both ajax and regular HTTP requests. Simplified, it looks like this: def tag_search(request, tag): items = Item.objects.filter(tags__tagname__exact=tag) if request.is_ajax(): return HttpResponse(serializers.serialize('json', items), mimetype='application/json') else:...

How to implement restful webservice with python/django

i try to setup a ubuntu server with web service that create by django/python , anyone have an resource/tutorial/example code ...

Recoding a Podcast Website - What should I use?

OK here is the deal. Me and some buddies are doing a Podcast(for over 4 year now) and in April we relaunched the site, that included a new Backend. Since I only had 2 weeks back then for getting everything to work, I decided to create something from scratch so everything fitted precisely our needs. The whole thing was written in Python b...

Django development server CPU intensive - how to analyse?

Hi folks, I'm noticing that my django development server (version 1.1.1) on my local windows7 machine is using a lot of CPU (~30%, according to task manager's python.exe entry), even in idle state, i.e. no request coming in/going out. Is there an established way of analysing what might be responsible for this? Thanks! Martin ...

How do I get something like repeat customers in Django

My models look something like this: class Customer(models.Model): name = models.CharField(max_length=100) class Order(models.Model): customer = models.ForeignKey(Customer) date = models.DateField() total = models.DecimalField(max_digits=5, decimal_places=2) I then have a queryset of orders: from datetime import datetime ...

What's the best way to create a 'history' type model in django?

I'd like to create a feature for my Django app similar to Django admin's 'Recent Actions', in order to store history information on my other models. For example say I have two models called Book and Author. I want to have a third model that stores information such as what action was performed on a given object in a model (add, modify, d...

How to manage Javascript modules in django templates?

Lets say we want a library of javascript-based pieces of functionality (I'm thinking jquery): For example: an ajax dialog a date picker a form validator a sliding menu bar an accordian thingy There are four pieces of code for each: some Python, CSS, JS, & HTML. What is the best way to arrange all these pieces so that: each javascr...

Get Intervals Between Two Times

A User will specify a time interval of n secs/mins/hours and then two times (start / stop). I need to be able to take this interval, and then step through the start and stop times, in order to get a list of these times. Then after this, I will perform a database look up via a table.objects.filter, in order to retrieve the data correspon...

Update HttpResponse Every Few Seconds.

My application in Django can create some very big SQL queries. I currently use a HttpRequest object, for the data I need, then a HttpResponse, to return what I want to show the User. Obviously, I can let the User wait for a minute whilst these many sets of queries are being executed and extracted from the database, then return this mon...