Skip to content
Advertisement

Tag: django

Can one use the Django database layer outside of Django?

I’ve got a nice database I’ve created in Django, and I’d like to interface with it through some python scripts outside of my website stuff. I’m curious if it’s possible to use the Django database API outside of a Django site, and if so does anyone have any info on how it can be done? Google hasn’t yielded many useful

django – inlineformset_factory with more than one ForeignKey

I’m trying to do a formset with the following models (boost is the primary): I want to display a form to add a Boost item, trying to do in this way : Here are my questions : 1 – When rendered, the combo box for “Creator” shows a list of “db.userInfo” (literally)! I want this to display db.userInfo.auth.username that is

Django TemplateDoesNotExist?

My local machine is running Python 2.5 and Nginx on Ubuntu 8.10, with Django builded from latest development trunk. For every URL I request, it throws: TemplateDoesNotExist at /appname/path appname/template_name.html Django tried loading these templates, in this order: * Using loader django.template.loaders.filesystem.function: * Using loader django.template.loaders.app_directories.function: TEMPLATE_DIRS (‘/usr/lib/python2.5/site-packages/projectname/templates’,) Is it looking for /usr/lib/python2.5/site-packages/projectname/templates/appname/template_name.html in this case? The weird thing is

Atomic increment of a counter in django

I’m trying to atomically increment a simple counter in Django. My code looks like this: If I understand Django correctly, this should wrap the function in a transaction and make the increment atomic. But it doesn’t work and there is a race condition in the counter update. How can this code be made thread-safe? Answer Use an F expression: either

match an alternative url – regular expression django urls

I want a Django URL with just 2 alternatives /module/in/ or /module/out/ I’m using But it matches other patterns like /module/i/, /module/n/ and /module/ou/. Any hint is appreciated :) Answer Try r’^(?P<status>in|out)/$’ You need to remove w+, which matches one or more alphanumeric characters or underscores. The regular expression suggested in bstpierre’s answer, ‘^(?P<status>w+(in|out))/$’ will match helloin, good_byeout and so

can’t see records inserted by django test case

I’m trying to provide integration to my django application from subversion through the post commit hook. I have a django test case (a subclass of unittest.TestCase) that (a) inserts a couple of records into a table, (b) spawns an svn commit, (c) svn commit runs a hook that uses my django model to look up info. I’m using an sqlite3

Get the index of an element in a queryset

I have a QuerySet, let’s call it qs, which is ordered by some attribute which is irrelevant to this problem. Then I have an object, let’s call it obj. Now I’d like to know at what index obj has in qs, as efficiently as possible. I know that I could use .index() from Python or possibly loop through qs comparing

Advertisement