django

GeoDjango distance search

I want to use GeoDjango to do basic location searches. Specifically I want to give the search function a ZIP code/city/county and find all the ZIP codes/cities/counties within 5mi, 10mi, 20mi, etc. I found the following paragraph in the documentation: Using a geographic coordinate system may introduce complications for the develope...

How to correctly modify <HEAD> in Django-CMS for custom plugins?

Django-CMS custom plugins and navigation extenders allow to create any content HTML in some part of the HTML . However I frequently have some JavaScripts required for some specific plugins, like a photo album viewer plugin that requires a JS in the . My current solution is to let the user specify a specific template for that. I could do...

Does anyone had success getting Django to send emails when hosting on Dreamhost?

Greetings, Does anyone know what are the required fields to have Django send emails when a "500 Internal Server Error" happend? I am hosting my project on Dreamhost and for the life of me I can't get Django to send emails. What are the required fields when hosting on Dreamhost? ...

Selected option in django dynamic choicefield

I create a keyword filter in django My views.py #.............. if request.method == 'POST': form = FilterContentForm(request.POST) else: form = FilterContentForm() if len(keyword_dict)!= 0 and keyword_dict['customer_type']: list_customer = filter(keyword_dict['customer_typ...

Django models generic modelling

Say, there is a Page that has many blocks associated with it. And each block needs custom rendering, saving and data. Simplest it is, from the code point of view, to define different classes (hence, models) for each of these models. Simplified as follows: class Page(models.Model): name = models.CharField(max_length=64) class Block...

Django KeyError when getting an object with a keyword for a field name

I wish to get an object in the following fashion: Collection.objects.get(name='name', type='library', owner=owner, parent=parent) Unfortunately type is a keyword as thus creates the following error: KeyError at /forms/create_library type Is there a way to disambiguate the meaning of the word type to allow me to specify a field of t...

Changing properties of inherited field

I want to alter properties of a model field inherited from a base class. The way I try this below does not seem to have any effect. Any ideas? def __init__(self, *args, **kwargs): super(SomeModel, self).__init__(*args, **kwargs) f = self._meta.get_field('some_field') f.blank = True f.help_text = 'This is optional' ...

Django index page best/most common practice.

I am working on a site currently (first one solo) and went to go make an index page. I have been attempting to follow django best practices as I go, so naturally I go search for this but couldn't a real standard in regards to this. I have seen folks creating apps to serve this purpose named various things (main, home, misc) and have see...

Correct way to use get_or_create?

I'm trying to use get_or_create for some fields in my forms, but I'm getting a 500 error when I try to do so. One of the lines looks like this: customer.source = Source.objects.get_or_create(name="Website") The error I get for the above code is: Cannot assign "(<Source: Website>, False)": "Customer.source" must be a "Source" ins...

Redirect with additional variables

Hello. I have view which in some cases redirects user to another addres. How can I redirect user, with additional variables (not GET, beacause that variable can be long text)? Currently I'm using HttpResponseRedirect. Cheers. ...

Why does Django throw an exception whenever I enable admin.autodiscover()?

Here is my setup. I am using Django version 1.1.1 on Dreamhost, Python 2.4. The problem I am having is whenever I create a simple app and also have admin.autodiscover() enabled, Django will throw an exception. My setup: from django.conf.urls.defaults import * from testapp.views import HelloWorld from django.contrib import admin admin.a...

Django error: got multiple values for keyword argument

I get the following error when instantiating a Django form with a the constructor overriden: __init__() got multiple values for keyword argument 'collection_type' The __init__() function (shown below) is exactly as written this but with # code replaced with my logic. Asside from that I am essentially overriding the form's (which is a ...

How can I access response.context when testing a Jinja2 powered Django view

When I use the Django test.client and I do something like: class MyTestCase(TestCase): def test_this(self): c = self.client response = c.get('/') assert False, response.context['name'] I get an error: assert False, response.context['name'] TypeError: 'NoneType' object is unsubscriptable My only guess is ...

How to organize a database in Django with multiple, distinct apps?

I'm new to Django (and databases in general), and I'm not sure how to structure the following. The sources of data I'll have for my site are: a blog for a few different games: a high score list user-created levels If I were storing the data in ordinary files, I'd just have one file for each of the above. In Django, ideally (I think...

How to redirect to a newly created object in Django without a Generic View's post_save_redirect argument

I'm trying to redirect a user to a newly created object's object.get_absolute_url() after saving a form. I'm not using a generic view, so I can't use the post_save_redirect argument. The relevant portion of the view is like so: if form.is_valid(): form.save() return HttpResponseRedirect(reverse('story_detail', args=(story.user, ...

Django - Loading templates from different project folder?

Issue: Beta site is pulling from primary site templates folder, below is a skeleton structure of the site folder structure - store is the hosted project dir for DOMAIN.com beta/store goes to beta.DOMAIN.com the site is hosted Dir Structure Project/ apache site.wsgi beta apache site.wsgi logs store [APP...

How to trigger django DEBUG on a production server non intrusively

I'm looking for a safe method of triggering DEBUG for INTERNAL_IPS requests on a django production server without requiring the alteration of a settings.py file. Mainly to get the toolbar going for some designers to check issues on live data/media, but without relying on them to reset the settings once they have finished. Similar to thi...

Why isn't count() working the way I expect in my code?

class FriendshipManager(models.Manager): def are_friends(self, user1, user2): if self.filter(from_user=user1, to_user=user2).count() > 0: return True if self.filter(from_user=user2, to_user=user1).count() > 0: return True return False and i found count() so ...

Use the same Django models across two different databases in the same app

I have a set of Django models that are used in two databases (i.e. syncdb was run against two databases from the same app). Both databases are for production services (one database contains on-demand "sandbox" build information and the other contains nightly build information). The problem is that I want to have one Django app that dis...

Django Development Server Not Serving Errors from Ajax Requests

Hello everyone, I've been trying to get some Ajax stuff to work in my Django application, but it has been difficult because for some reason syntax and type errors are not causing a server crash and are failing silently. How could this be? JavaScript (jQuery): add_foo = function() { var numfoos = $("div#foos_container > div.foo").l...