django

How to serialize to json format a queryset that use the 'extra' statement in Django?

Hi, I want to serialize a QuerySet that contains an extra statement: region_list = Region.objects.extra(select={ 'selected': 'case when id = %s then 1 else 0 end' % (new_region.id)}).all() I use the statement below to serialize return HttpResponse(serializers.serialize('json', region_list), mimetype='application/json') But when I o...

How can reverse('opensearch') work in the shell, but fails in a Test?

I'm trying to install django-lean into my application. Open search is used in my app App. I can reverse('opensearch') in the Python shell. However, in the test, reverse('opensearch') * NoReverseMatch: Reverse for 'opensearch' with arguments '()' and keyword arguments In [47]: reverse('opensearch') Out[47]: '/opensearch.xml' In [48]:...

Interestinting situation. DataBase Error? Python. Django.

In test server it is working. But production gives this traceback: what different? And what does that error mean? Different is only in python versions. In test server it is 2.6.5 and production 2.5.2. How can I get rid of this error with out changing version? True 2008-10-16 15:20:00 - did not match our database Traceback (most recen...

Analyse data using time and date objects

I have a rather unique problem I'm trying to solve: Based on this sample data (actual data is very many records, and at least 4 per card per day): serial, card, rec_date, rec_time, retrieved_on 2976 00040 2010-07-29 18:57 2010-07-31 13:37:31 2977 00040 2010-07-30 09:58 2010-07-31 13:37:31 2978 00040 2010-07-30 15:33 2010-07-31 13:3...

Two classes: one for the django model and one for representing the data outside of django

Is there a reasonable pattern for handling an object that exists as a Django model within the context of a particular Django application and as a non-Django class outside of that particular application? For example, let's say that I have a Post model within Django application Blog. I want to be able to interact with a class representing...

How customize one field on the django admin interface

I have a model in my django project with a member which is a char field. Basically data in this field will be entered as comma-separated values Without a long-winded explanation of what the overall goal of this is, basically rather than having the admin interface use a simple text field, I'd rather have have some custom HTML for the fo...

Getting IOError when using pre_save signal to store a thumbnail

I have a model that has an option photo field. When a photo is added, I want a thumbnail to be automatically created and stored. However, when I do this with a pre_save signal, I keep getting an IOError, and if I try to do it with a post_save signal I can't save the thumbnails path to my model without creating and infinite post_save loop...

Prevent syncdb from updating database in Django?

I'd like to respect the database as a "read-only" and never write to it. Is there a way to easily prevent syncdb from even bothering to check to update the database? With Django 1.2 and the ability to have multiple databases, it'd like to be able to query a database for information. I'd never need to actually write to that database. ...

python confusion: dict.pop

I am really confused as to why Python acts in a particular way. Here is an example: I have a dictionary called "copy". (It is a copy of an HttpRequest.POST in django.) Here is a debug session (with added line numbers): 1 (Pdb) copy 2 <QueryDict: {u'text': [u'test'], u'otherId': [u'60002'], u'cmd': [u'cA'], u'id': 3 [u'15']}> 4 (Pdb) ...

Python framework for building ad serving application (like AdSense)?

What Python web framework (Django?, Pylons?, ...) suitable for building ad serving application (like AdSense)? ...

How force user to fill forms before do something else ?

Hi guys, i would like to know how force user to fill forms before do something else. I have a private area, i need the user's fill the forms, there's 4 forms, (is a job's board). a) i want fill the forms with wizardforms, but how force to do it? Sorry with my english Thanks ...

Django last thirty days added with number

With a model like this: class User(models.Model): entered = models.DateTimeField(auto_now_add=True) How to grab stats data so it show recent added users for last 30 days with number of users added on that day. Example: 2010-08-02: 220 2010-08-08: 1220 2010-08-14: 20 ...

Passing an array in django urls

Can we pass an array to a django url <script> function save() { window.location = "/display/xlsdisplay/" + objarr ; } var objarr = new Array(); </script> Urls.py (r'^xlsdisplay/(?P<qid>\d+)$', 'xlsdisplay'), There is an error saying http://192.168.1.11/display/xlsdispla...

querying a array in django

idarr = [1,2,3,4,5] for i in range(len(idarr)): upload.objects.filter(idarr[i]) Cant we pass the idarr at one shot to the query ...

django ModelForm for subclassed models : Error for one, but not for another ('NoneType' object has no attribute 'label')

I'd like to ask for you guidance in the following matter in django: I am using the following models: class QItem(models.Model): isWhat = models.CharField(max_length=100, blank=True, choices=ISWHAT) slug = models.SlugField(blank=True) script = models.CharField(max_length=100) comment = models.TextField(blank=True, null=...

Embed html into an existing div

When the html is returned from django views <script> //The following is in the ready function $("#data").html("{{dict.html}}"); </script> <div id="data" name="data" style="display:block;"></div> The following html is displayed on the screen.How to embed this html into data div <ul ><li ><a ><ins> </ins>Ses</a><ul...

Pass array from HTML to Django application

Hi, I developed an application in JSPs and Servlets involving drop down menus that kept growing with how many authors per publication their were. This was done in Javascript and then in my application iterated through them using a loop. Is this possible using django? As this would be useful in my application? Thanks in Advance, Dean ...

How to customize django's UserCreationForm?

I want to customise the django.contrib.auth UserCreationForm to: Ignore the email field, and only display a user-name which must be an email address Prompt the user for first name and last name. I'm using django-registration if that makes a difference. How can I do this? I can subclass the form, but how do I tell the auth system to...

Django query select distinct by field pairs

I have the field 'submission' which has a user and a problem. How can I get an SQL search result which will give a list of only one result per user-problem pair? Models are like this: class Problem(models.Model): title = models.CharField('Title', max_length = 100) question = models.TextField('Question') class Submission(models...

How to retrieve the django user profile object in a view?

Is there an easy way to access the user's profile in a view, something like user.profile.my_field? ...