django

Disable autocommit during hundreds of MySQL UPDATE statements in Django program

In a Django program, how to explicitly disable auto transaction management before hundreds of UPDATEs and enable it after the UPDATEs finish? I looked into http://docs.djangoproject.com/en/dev/topics/db/transactions/ but didn't find any clue. I tried to put the following code at the beginning settings.DISABLE_TRANSACTION_MANAGEMENT = ...

Django's performance on serving static files

I am prototyping a Django web-app that will provide a static media files (PDFs, movies and so on) to the users. One of the features I am going to implement is a dynamic URLs. The point is to generate different URLs for each access attempt. When user will request a list of files I will generate links and save them to the DB. When some of ...

django save_m2m() not working.

Utterly stuck trying to update a ManyToManyField field on POST and save. Models.py class Location(models.Model): place = models.CharField(max_length=100) inuse = models.BooleanField() class Booking(models.Model): name = models.CharField(max_length=100, verbose_name="Your name") place = models.ManyToManyField(Location, ...

Django / Python, Make database save function re-usable (so that it takes modelname and appname from strings), using contenttypes or some other method?

I want to make some functions that are re-usable by any model so that I can specify the appname and model in string format and then use this to import that model and make calls to it such as creating database fields, updating, deleting, etc... I had thought I could do this using contenttypes in Django but am trying this, as below and am...

How to reset global variable in python?

SOME_VARIABLE = [] def some_fun: append in SOME_VARIABLE s = [] s = SOME_VARIABLE SOME_VARIABLE = [] // Not setting to empty list. return s How to reset SOME_VARIABLE to empty. ...

assign unique ID to django comments form

I am building a similar wall feature to what facebook has, comments etc. I am making use of django's comments framework and jquery to post and get on success, and I am looking at a way of extracting the the hidden id_object_pk's value and using that also as the forms id Your normal form is rendered in the following way. <form action="...

Django's 500.html doesn't work

I want to use my own page for 500 errors. So I've put a 500.html in my templates root directory. But when an error occurs the default apache 500 page is displayed. I did the same with the 404.html and this one just works fine. Has anyone an idea what the problem could be? ...

How to force-save an "empty"/unchanged django admin inline?

I have some inlines in one of my admin models which have default values which likely won't need to be changed when adding a new instance with "Add another ...". Unfortunately django won't recognize these inline as new objects unless some value has changed. This forces me to add an inline, change an arbitrary value, save, change the value...

Testing workflows in Django

Hi folks, I really love testing and building unit tests, but I find it quite annoying having to build tests for a website's workflow. e.g. Register -> Check email -> Activate account -> Login or Login -> Edit details -> Submit and view profile manual testing = loads of time + tireing even when using app such as Selenium, going t...

Why can't I set DEBUG=False in my django app on dreamhost without getting an error?

Hi, I have successfully been running my django based page for some time. Now I thought I'd turn of debug mode and implement a nice 404.html file. The problem is that as soon as I change DEBUG to 'False' in my settings.py I immediately get server errors that I don't understand, no matter what page I try to visit. Existing pages or non-ex...

speeding up mysql queries / mysql views in django

I use the following code to select popular news entries (by date) from the database: popular = Entry.objects.filter(type='A', is_public=True).extra(select = {'dpub': 'date(dt_published)'}).order_by('-dpub', '-views', '-dt_written', 'headline')[0:5] To compare the execution speeds of a normal query and this one I ran the following mysq...

Why does my dead simple Django app keep crashing python on my mac 10.6.4?

views.py from django.shortcuts import render_to_response from django.shortcuts import get_object_or_404 from django.shortcuts import get_list_or_404 from django.template.context import RequestContext from articles.models import Article def index(request): articles = get_list_or_404(Article) return render_to_response( '...

Django model per table vs model per select

Hey, I am working with Django for a while and now that my "tree" and whole DB is filled with data (note: existing database), I was wondering if the "one model per table" is really better at this point than "one model per select". I have got one table - objtree. This is the place where I have all nodes (brands, categories, tags, etc.) ...

Django, simplest forloop, how? (i=0; i<20; i++)

I just need to generate some test content for my template. Something like: {{ for i < 20 }} <img src="image-{{i}}.jpg " /> {{ endfor }} I have no list, how should I proceed? ...

Customize save path for ImageField

I want to customize the folders that are used to save my images for a record...currently, I have: original_image = models.ImageField(upload_to='photos') But what I want to have is the images being saved to photos/<vehicle's_stock_number>/...how can I add the stock number to the end of the upload path? ...

Why does django not see my tests ?

I've created test.py module, filled with from django.test import TestCase from django.test.client import Client from django.contrib.auth.models import User from django.contrib.sites.models import Site from forum.models import * class SimpleTest(TestCase): def setUp(self): u = User.objects.create_user("ak", "[email protected]", ...

TinyMCE in Django Template

Using django-tinymce I have successfully embedded TinyMCE in the Admin before. Embedding it in a front-end form does not seem to work for me however. I have a form which is a modelForm. It doesn't add any extra fields ('comment' and 'statement' are the only fields used and they exist in the model). On the textarea field, 'comment', of t...

Django Celery AbortableTask usage

I'm trying to use the AbortableTask feature of Celery but the documentation example doesn't seem to be working for me. The example given is: from celery.contrib.abortable import AbortableTask def MyLongRunningTask(AbortableTask): def run(self, **kwargs): logger = self.get_logger(**kwargs) results = [] for ...

When a Web framework isn't convenient to use ?

When a Web framework ( like django, ruby on rails, zend, etc ) isn't convenient to use ? And so... When a Web programming language ( like PHP, Asp, Python, etc ) is better than a Web Framework ? ...

Is it possible to pass SafeData instances to Django templates?

I know that it's possible to have a template filter return a SafeData instance by doing something similar to the following. from fictitious import guaranteed_safe from django.utils.safestring import mark_safe def myfilter(text): return mark_safe(guaranteed_safe(text)) My question is whether it's possible to "mark as safe" variab...