django

how to get a certain number of elements from the database django

I have a simply class class BlogPost(models.Model): title = models.CharField(max_length=150) ... timestamp = models.DateTimeField() How do I get the last five items from the database. I tried to do like this: posts = BlogPost.objects.<any code> Excuse me for bad English ...

django permalink error

Hi all! I have a page with some years. I want to click over the year, for instance 2000, to see all the information. What I have in urls is this: url(r'^browse/time/(\d{4})/$', 'TBDBsite.tb.views.data_time', name="yr"), In models: @permalink def get_absolute_url(self): return('year', [str(self.date.year)]) And in the tem...

How to avoid NotImplementedError "Only tempfile.TemporaryFile is available for use" in django on Google App Engine?

I'm using django 1.1 on Google App Engine through use_library. No django gae helper, django-nonrel or similar tools are used here. Django handles urls routing, forms validation etc., but I'm using pure appengine models. In one of my django's forms there is a FileField, which from time to time seems to call django.core.files.uploadedfile...

django modeladmin list_display

I'm trying to play with the Django's official tutorial. Specifically the modeladmin list_display: http://docs.djangoproject.com/en/1.2/intro/tutorial02/#customize-the-admin-change-list How can I add a column that displays the number of choices for each poll in the list? Thanks! ...

Foreignkeyfield - verbose name not shown in form

Hi there, my verbose_name of a foreignkeyfield isn't printed in my forms. (I create the modelforms via modelformset_factory model class MOrders(models.Model): amount = models.IntegerField('Bestellmenge', null=True, blank=True) order_date = models.DateField('Bestelldatum') id = models.AutoField(primary_key=True) m_produ...

Python error, only in the command window. Causes site to hang when loading.

I receive this error when files are loading and sometimes after they have stopped loading. It only happens with this site, not with my other django sites. I can't make any sense of this one. Can anyone tell me what's going wrong here? ...

filtering by calculated (extra()) fields

Hi, does anyone know a way of filtering a QuerySet by a field that was added through the extra() method? For example, this is what I would like to do _list_items = ListItem.objects.filter(list=1).extra(select= 'SELECT value AS "type" FROM list_item_optional WHERE list_item_optional.list_optional_id=1 AND list_ite...

Facebook connect with django/python

I've been stuck on this for a while. I can't seem to get facebook login to pop up when following the google tutorial: <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"&gt;&lt;/script&gt; <div id="fb-root"></div> <script src="http://connect.facebook.net/en_US/all.js"&gt;&lt;/script&gt; <script> FB.init({app...

Django, database retrieval not working but deleting fields and adding new fields is working

I have been able to get my database queries to work properly for deleting existing entries and also adding new entries to the database but I am completely stumped as to why I am unable to retrieve anything from my database. I am trying a query such as: from web1.polls.models import Poll retquery = Poll.objects.all() print retquery --pri...

Regarding codes gluing django and facebook

I'm building a website using django and planning to connect it with facebook. I googled and found so many codes to do the job but don't know which one is good for me. I need facebook connect and new graph api support. Could anyone share me some experiences with codes below and advise me which one is good for me? (with some tips if possbi...

Eliminating extra DBQueries in django by storing the absolute_url

Using Django blogging, I have a template that looks like: <a href="{{ post.get_absolute_url }}">{{ post.title }}</a> This looks innocuous enough, but it ends up generating yet another lookup of the user of the blog post, something that I (in most cases) already know. However that isn't my point. The URL looks like: http://localhost...

Generating dynamic CSS

What is the best way to handle style that that is user-customized? Just as an example of the result I'm looking for, this would suffice: body { color: {{ user.profile.text_color }}; } However, serving CSS as a view seems like it would cause a significant amount of overhead in a file that is constantly requested, so this is probably...

django static annotation

Hi, I want to add a static value to the results of a database query using django (so not using 'raw' SQL) For example, if I have an object Car with fields make, model, and color, then I want my results set with extra static value to look something like this: make model color sales ---- ----- ----- ----- nissan ...

django annotation and filtering

Hi, Hopefully this result set is explanatory enough: title text total_score already_voted ------------- ------------ ----------- ------------- BP Oil spi... Recently i... 5 0 J-Lo back ... Celebrity ... 7 1 Don't Stop... If there w... 9 0 Austr...

Django - make file I/O thread safe

Hi, I want to read and write python-source-files from the file system in a thread-safe way. open("n2.py","w").write(my_new_py_class) from myproject import n2 #do something with n2 I assume that this is not thread-safe, since a request2 could modify the file before request1 is loading and executing it. I would like to achieve somethin...

PHP website with RESTful API using Django. Possible? Good Idea?

I have an existing website written in PHP. I would like to add a REST API. I like how easy creating a RESTful API was using Django. Are there any CONS for using Django for the sole purpose of creating an API on a PHP powered website? Thanks in advance. ...

Output of proc.communicate() does not format newlines in django python

I have a subprocess using communicate to get the output ans saving it to my database: p = Popen([str(pre_sync), '-avu', str(src), str(dest)], stdout=PIPE) syncoutput = p.communicate() check.log = syncoutput It all works fine, but the output from communicate looks like this: ('sending incremental file list\n\nsent 89 bytes rece...

How to make cookie-setting javascript cooperate with django.contrib.auth?

Hi I'm trying to make mathjax work in askbot Q&A forum. Got some decent results, but here is a strange issue: once I add some setting (a feature in mathjax that uses cookies) via right-clicking - django automatically logs me out. Is there a way to make django authentication not over-react to cookies set via javascript? Thanks. ...

django weighted questionnaire?

Hello, I've been learning django off and on for a few years now and consider myself an advanced beginner, ha. I'm working on a "weighted questionnaire" (that's the best name I can give it anyway) for a client and have gone in circles about where to go with it. The client has come up with a series of yes or no questions and depending o...

Google App Engine w/ Django - InboundMailHandler appears to only work once

I'm writing an app for Google App Engine (with Python and Django) that needs to receive email and add some elements of the received email messages to a datastore. I am a very novice programmer. The problem is that the script I specify to handle incoming email appears to only run once (until the script is touched). Sending a test email ...