django

Adding REST to Django -- Poll

I've got a Django application that works nicely. I'm adding REST services. I'm looking for some additional input on my REST strategy. Here are some examples of things I'm wringing my hands over. Right now, I'm using the Django-REST API with a pile of patches. I'm thinking of falling back to simply writing view functions in Djang...

How to quote a string value explicitly (Python DB API/Psycopg2)

Hello, For some reasons, I would like to do an explicit quoting of a string value (becoming a part of constructed SQL query) instead of waiting for implicit quotation performed by cursor.execute method on contents of its second parameter. By "implicit quotation" I mean: value = "Unsafe string" query = "SELECT * FROM some_table WHERE s...

In Django, Problem with {{ block.super }}, How do I avoid duplicating a `block` in multiple template files?

For 2 child template files inheriting a block, the {{ block.super }} does not resolve Python 2.5.2, Django 1.0, Windows XP SP3 Sample skeleton code for files involved: base.html item_base.html show_info_for_all_items.html show_info_for_single_item.html FILE : base.html {% block content %} {% endblock %} FILE : item_base.html {%...

In Django, how does one filter a QuerySet with dynamic field lookups?

Given a class: from django.db import models class Person(models.Model): name = models.CharField(max_length=20) Is it possible (and if so how) to have a QuerySet that filters based on dynamic arguments, likeso: # instead of Person.objects.filter(name__startswith='B') # and Person.objects.filter(name__endswith='B') # is th...

Does anyone know of a python based web ui for snmp monitoring?

Comparable to cacti or mrtg. ...

using rstrip on form.cleaned_data[i] in Django

In my views.py, i have a snippit of code like this: def clean_post_data(form): for i in form.cleaned_data: form.cleaned_data[i] = form.cleaned_data[i].rstrip() def add_product(request): form = ProductForm(request.POST, request.FILES or None) image = Image.objects.all() action = "Add" if request.POST: i...

Cleaning form data in Django

How can i clean and modify data from a form in django. I would like to define it on a per field basis for each model, much like using ModelForms. What I want to achieve is automatically remove leading and trailing spaces from defined fields, or turn a title (from one field) into a slug (which would be another field). ...

Which RDBMS do you use with Django and why?

I recently switched a project from MySQL InnoDB to PostgreSQL, and I feel bigger lags when inserting and updating data with ajax. This may be subjective. I know the Django devs recommend postgres and I know psycopg2 is supposed to be faster than MysqlDB. Personaly I like the way postgres enforces database integrity, but am mostly worried...

How do I edit and delete data in Django?

I am using django 1.0 and I have created my models using the example in the Django book. I am able to perform the basic function of adding data; now I need a way of retrieving that data, loading it into a form (change_form?! or something), EDIT it and save it back to the DB. Secondly how do I DELETE the data that's in the DB? i.e. searc...

Admin generic inlines for multi-table subclassed models broken --- any alternatives?

Here's what I'm trying to do, and failing... I have a File model which has a generic-relation to other objects: class File(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey() file = models.FileField(upload_to='files/%Y/%m/%d'...

No Module named django.core

Hi, I have updated to latest Django version 1.0.2 after uninstalling my old Django version.But now when I run django-admin.py I get the following error. How can I resolve this? Traceback (most recent call last): File "C:\Python25\Lib\site-packages\django\bin\django-admin.py", line 2, in <module> from django.core import management...

Django authentication and Ajax - URLs that require login

I want to add some Ajax-niceness to my Django-coded website. In my Django code, I use the @login_required decorator from django.contrib.auth.decorators to mark which view requires authentication. The default behavior when a not authenticated user clicks it is to redirect him/her to login page, and then pass the target page. What I sa...

Django Admin Interface Does Not Use Subclass's __unicode__()

Hello, (Django 1.x, Python 2.6.x) I have models to the tune of: class Animal(models.Model): pass class Cat(Animal): def __unicode__(self): return "This is a cat" class Dog(Animal): def __unicode__(self): return "This is a dog" class AnimalHome(models.Model): animal = models.ForeignKey(Animal) I have instantiated n...

Using django how can I combine two queries from separate models into one query?

In my specific case, I have two kinds of "messages" that I need to retrive and paginate. Let's omit the details, and just say that the first kind is in a model called Msg1 and the other is called Msg2 The fields of these two models are completely different, the only fields that are common to the two models are "date" and "title" (and o...

Are there problems developing Django on Jython?

The background I'm building a fair-sized web application with a friend in my own time, and we've decided to go with the Django framework on Python. Django provides us with a lot of features we're going to need, so please don't suggest alternative frameworks. The only decision I'm having trouble with, is whether we use Python or Jyth...

How does one set up multiple accounts with separate databases for Django on one server?

Hi there, What options are there for installing Django such that multiple users (each with an "Account") can each have their own database? The semantics are fairly intuitive. There may be more than one User for an Account. An Account has a unique database (and a database corresponds to an account). Picture WordpressMU. :) I've conside...

Spambots are cluttering my log file [Django]

I have a nice and lovely Django site up and running, but have noticed that my error.log file was getting huge, over 150 MB after a couple of months of being live. Turns out a bunch of spambots are looking for well known URL vulnerabilities (or something) and hitting a bunch of sub-directories like http://mysite.com/ie or http://mysite.co...

How do i use the change_form.html template in django?

I have my models and i would like to make use of the Django change_form template to edit my data, currently i have created my own template that works fine but lacks some of the basic stuff that change_form template might have, like fields validation. Please give examples showing how i should call the template from my view, and what obje...

How to upload a file with django (python) and s3?

I'm looking for a way to upload a file to s3. I am using django. I am currently using amazon's python library for uploading along with the following code: View: def submitpicture(request): fuser = request.session["login"] copied_data = request.POST.copy() copied_data.update(request.FILES) content_type = copied_data['file'].get('conte...

Django: How can I protect against concurrent modification of data base entries

If there a way to protect against concurrent modifications of the same data base entry by two or more users? It would be acceptable to show an error message to the user performing the second commit/save operation, but data should not be silently overwritten. I think locking the entry is not an option, as a user might use the "Back" but...