django

Run custom Django management command over SSH

I have a Django application with a custom management command in one of the apps. If I log in over SSH I can run it without any problems with python manage.py sitedir/mycommand However, if I try to run the command as a oneliner from my local box like this: ssh myserver python manage.py sitedir/mycommand I get an ImportError li...

Conditionally including content into Django 1.2 templates

How can I include with Django what Symfony calls 'components' - bits of logic and a template that's not associated with the content of the current page? For example I want to include a sidebar that displays a list of the top 10 articles on the site. It should always be displayed if the user is looking at either an 'article' page or a 'v...

How to write a request filter / preprocessor in Django

I am writing an application in Django, which uses [year]/[month]/[title-text] in the url to identitfy news items. To manage the items I have defined a number of urls, each starting with the above prefix. urlpatterns = patterns('msite.views', (r'^(?P<year>[\d]{4})/(?P<month>[\d]{1,2})/(?P<slug>[\w]+)/edit/$', 'edit'), (r'^(?P<ye...

Django models and multilingual websites

I have a model that has multiple text properties - title, short and long description etc. I want to have multilanguage site so I need a way to easy by able to add new languages and translations for this field for every item. What is the best way to achieve this? ...

Many-To-One Relation Query in Django

Hi, Can someone tell me, how I can access all contacts relating to a specific group? I'm new to Django and did this (according to the docs): def view_group(request, group_id): groups = Group.objects.all() group = Group.objects.get(pk=group_id) contacts = group.contacts.all() return render_to_response('manage/view_group...

Can i get models field type from a model queryset in Django?

Can i get model field type from a model queryset in Django? For example: a is b model's queryset and the b model has following fields: f:charfield g:foreignkey h:manytomany Is there any way to get field g's type from queryset a? thx. ...

How can I add user profile support to a google app engine app?

I have a Google App Engine app based on django / django_appengine that I wish to modify by adding user profile support to it, because the basic user model is a bit simplistic for my situation. What's the best way to do this? ...

Django Model data incomplete

I have a model with 6 fields, but when I access them using the author field and print the result, it only displays 4 of them, field5 is not shown. The admin shows all fields. My view, model and modelform are below. if request.POST: c1 = Datastore.objects.get(author = request.user) return HttpResponse(c1) class Datastore(models...

jQuery AJAX request gets called twice when using Jquery, Django and Google App Engine

I'm using Google App Engine, Jquery and Django. I want POST data to be sent to the server side when a form is submitted, and I do this in JQuery with the following code: $("#listform").submit(function() { $.ajax({ type: "POST", url: "/xhrtest", data: {'name': 'h...

How do I redefine functions in python?

I got a function in a certain module that I want to redefine(mock) at runtime for testing purposes. As far as I understand, function definition is nothing more than an assignment in python(the module definition itself is a kind of function being executed). As I said, I wanna do this in the setup of a test case, so the function to be rede...

How do I access outer functions variables inside a closure(python 2.6)?

From wikipedia I need to access outer functions variables in a similar manner as using the 'nonlocal' keyword from python 3.x. Is there some way to do that in python 2.6? (Not necessarily using the nonlocal keyword) ...

[Django] Insert params into database as full object?

hi, un rails i can simply insert the params into the database with one command, when all form-field names are the same like the model-field names. is this possible in django as well, or do i have to set each param individually. i have like 20 fields, so it's a bit of a mess.. :) something like: blah = Contact() blah.content = params[]...

Security considerations - office website/portal on GAE

If one needs to create an office website (that serves as a platform for clients/customers/employees) to login and access shared data, what are the security considerations. to give you some more detail, The office portal has been developed in django/python and hosted through GAE. Essentially, the end point comes with a login/password to...

Django admin - How can I add the green plus sign for Many-to-many Field in custom admin form

The green plus sign button for adding new instances in the admin form disappears for my MultiSelect field (photos) when I define it in my form. Ie, removing the line with the definition (photos = ...) makes the plus sign appear. However, in order to use a custom Field/Widget I need to figure this out. class GalleryForm(ModelForm): ...

'WSGIRequest' object has no attribute 'user'

I'm new to django and Google App Engine, and I'm having trouble with using the datastore. Every time I make a query, such as db.GqlQuery("SELECT * FROM Listing ORDER BY date DESC LIMIT 10") I receive the error: 'WSGIRequest' object has no attribute 'user' This error seems to be generated in context_processors.py within the django c...

from list to select menu in django

I thought I had it figured out but now I'm missing something. First I have a QuerySet, records records = Record.objects.all() Now I want to make this into a list of one of the columns of the table, columnA alist = records.values_list('columnA') And then I want to pass this list in as a parameter to a custom form. FilterForm(alist...

django, distinct() not behaving

For some reason duplicate values aren't eliminated. records = Records.objects.all() records2 = records.values_list('columna','columna').distinct() print records2 I must be doing something stupid ...

What is the difference between starting a server binding to 0.0.0.0 vs 127.0.0.1?

It seems that Rails and Django can both start up the server binding to an IP, either 0.0.0.0, 127.0.0.1, or 192.168.1.2 <-- the last one is my local IP are there other choices? It seems that 0.0.0.0 and 192.168.1.2 can let a Virtual PC on the same machine access this website, while 127.0.0.1 cannot. However, if it is just the same ...

Repopulate django form

Wanted effect is passing the id to the request handler and populating the form with that entity. How doable is it with a template? Here are my form, request handler and template class AForm(djangoforms.ModelForm): text = forms.CharField(widget=forms.Textarea(attrs={'rows':'11','cols':'70','class':'foo'}),label=_("content").capitaliz...

Django/python is converting my post data from JavaScript

When I post a JSON string to Django by Ajax, it converts it into an invalid JSON format. Specifically, if I look in the post data in Firebug I am sending: info {'mid':1,'sid':27,'name':'aa','desc':'Enter info' } Yet when I access it in the django request I am seeing: u'{\'mid\':1,\'sid\':27,\'name\':\'aa\',\'desc\':\'Enter Info\'}...