django

Convention for checking the existence of a Django model?

What is the accepted way of checking a model's existence in a Django app? I've seen this method used: def profile_exists(user): try: UserProfile.objects.get(user = user) return True except: return False Is there a built-in function suited for this purpose? ...

where does defined the Table 'test.sphinx_test_file' ???

look the end line:ProgrammingError: (1146, "Table 'test.sphinx_test_file' doesn't exist") Traceback (most recent call last): File "D:\Python25\Lib\site-packages\django\core\servers\basehttp.py", line 280, in run self.finish_response() File "D:\Python25\Lib\site-packages\django\core\servers\basehttp.py", line 319, in finish_res...

why my django code can not be a 'Standalone Django scripts'

before you look my code , see http://www.b-list.org/weblog/2007/sep/22/standalone-django-scripts/ i want to be a Standalone Django scripts' this is my code : from django.db import models from djangosphinx.models import SphinxSearch,SphinxQuerySet import os os.environ["DJANGO_SETTINGS_MODULE"] = "sphinx_test.settings" from django.c...

Django model with filterable attributes

I've got two models. One represents a piece of equipment, the other represents a possible attribute the equipment has. Semantically, this might look like: Equipment: tractor, Attributes: wheels, towing Equipment: lawnmower, Attributes: wheels, blades Equipment: hedgetrimmer, Attributes: blades I want to make queries like, wheels = A...

How should I setup my homepage in django?

I'm not familiar with django conventions at all so if you do provide advice could you be specific Considering my homepage would contain components of articles: In Zend, in my IndexController I would create models and populate the view with articles and data. What's a convention/structure I could use for the homepage view ( sh...

SQL LIKE in Django/Python

I'm trying to run a query like this: SELECT * FROM MyTable WHERE FirstName LIKE '%[user inputted value here]%' OR LastName LIKE '%[that same user inputted value]%' AND UserID = some number When I run the query using cursor.execute(), the inputted values are going to be escaped and quoted, which is causi...

why 'list index out of range' in my django code;

IndexError: list index out of range this is my django code : import os os.environ["DJANGO_SETTINGS_MODULE"] = "sphinx_test.settings" #from django.core.management import setup_environ #from sphinx_test import settings #setup_environ(settings) from django.db import models from djangosphinx.models import SphinxSearch,SphinxQuerySet ...

django : recaptcha : Error in firefox works in IE & chrome : RecaptchaState error

I have integrated Recaptcha with dJango. dJango Snippet - Recaptcha The view which is showing the page is - from baseapp.recaptcha import captcha def showHome(request): if(request.user.is_authenticated()): tempEmail = request.session.get('id') return render_to_response('logreg/login-register.html', ...

what is the simplest way to create a table use django db api ,and base on 'Standalone Django scripts'.

we can call this 'Standalone Django table' i am not successful now . can you ??? thanks if you don't know 'Standalone Django scripts', look this http://www.b-list.org/weblog/2007/sep/22/standalone-django-scripts/ 2.this is my code: from django.core.management import setup_environ from sphinx_test import settings setup_environ(...

Django redirecting to external url that contains parameters (for development)

When developing with Django without a web server (serving directly from Django) I have a problem with external urls that lack the domain part and have parameters. Let's say I'm using a javascript library that does an ajax call to "/prefix/foo/bar?q=1" (the url is not something I can change). It is not a problem for the production serve...

Why can't I do a hyphen in Django template view?

{{profile.first-name.value}} My variable is hypeh only...I wish I could do first_name, but many variables are hyphens. However, due to this problem, I can't display my variables in the template. Why? ...

Django model class methods for predefined values.

I'm working on some Django-code that has a model like this: class Status(models.Model): code = models.IntegerField() text = models.CharField(maxlength=255) There are about 10 pre-defined code/text-pairs that are stored in the database. Scattered around the codebase I see code like this: status = Status.objects.get(code=0)...

How to store python classes into a database with Django ?

Hi, I have two files: choices.py class SomeChoice: name = u"lorem" class AnotherChoice: name = u"ipsum" # etc... models.py from django.db import models import choices class SomeModel(models.Model): CHOICES = ( (1, choices.SomeChoice.name), (2, choices.AnotherChoice.name), # etc... ) so...

How can _meta.local_fields not match the table schema in the database?

I'm completely confused about why _meta.local_fields returns more fields than the database table contains. The User model inherits from contrib.auth.models.User. $ mysql -u user -p database Enter password: Reading table information for completion of table and column names You can turn off this feature to get a quicker startup wit...

Django debug display all variables of a page

Is there a template tag (or any other trick) I can use to display all the variables available in a page? ...

cache.fetch in Django?

Does Django caching have a method similar to Rails' cache.fetch? (http://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html#M001023) The rails cache fetch works like: cache.fetch("my_key") { // return what I want to put in my_key if it is empty "some_value" } It's useful because it checks the cache, and returns the value ...

django-filebrowser not accessible and a 404 is thrown

Page not found (404) Request Method: GET Request URL: http://beta.mysite.com/admin/filebrowser/ The requested admin page does not exist. django-filebrowser requirements: django 1.0+ ( I have 1.1 ) PIL ( I installed python-imaging ) Grappelli ( I installed the latest svn trunk, confirmed it works ) For filebrowser ...

(django initial setup) Django installation is redirecting all traffic to django page, fix?

I'm a complete newbie to Django. I've been trying to get it working on my Ubuntu server. everytime someone my server, it redirects to the "Congratulations on your first Django-powered page." It completely ignores the index.html file in the www directory. Why is that? Is there a away to make it so that it only goes to the django page whe...

Django: Making ForeignKey not create a back-reference

I know that I can use ForeignKey's related_name argument to control what the back-reference's name will be. But is it possible to avoid creating a back-reference completely? (e.g., I have in Car a field ForeignKey(Person), and I don't want Person to have an attribute that leads backs to Car.) ...

how to select orphan records from model where referential integrity is not enforced?

Given the following models implemented in sqlite3 class Parent(models.Model): pass class Children(models.Model): parent=models.ForeignKey(Parent,primary_key=True) After importing data from a spreadsheet into Children I need to get a list of Parents having no children and for this I'm using... Parent.objects.filter(children__...