django

How/where to stop Django Formwizards 'done' method being called on payment failure

Hi there, I've looked through the django documentation, done lots of googling and have tried quite a few different solutions but to no avail. I've created a 3 part form using Django's FormWizard. Once the last form (a payment form) is validated, I send a payment request to a payment gateway. I'm doing the payment processing in the 'pro...

In Python, how do I check that a file is a text file?

The file is uploaded through a Django form. The contents of the file need to be saved into a models.TextField(), for editors to review it before publication. I am already checking UploadedFile.content_type. I have considered using a regular input field, but as the text is going to be quite long, it would be unwieldy for users to cut and...

How to implement non-database backed models in Django?

I have an existing Django application with a pretty typical model implementation that's backed by a database. My task is to change this model so that instead of fetching the information from a database, it now fetches it from a service (e.g., via HTTP). Because there is existing code which already makes use of this model, it would be nic...

Django Admin: How do I set the ordering of inline elements?

With a normal ModelAdmin class I can set the ordering with: ordering = ("field_name",) There seems to be no option to set ordering for InlineModelAdmin. Is there a way to get the inline elements to sort by a particular field? ...

Overwrite method add for ManyToMany related fields

Where should I overwrite method add() for ManyToMany related fields. Seems like it is not manager 'objects' of my model. Because when we are adding new relation for ManyToMany fields we are not writing Model.objects.add(). So what I need it overwrite method add() of instance. How can I do it? Edit: So i know that there is ManyRelate...

Django:How can I ensure that a view can only be directed from another view

I have two views def view1(request): do something return HttpResponseRedirect(reverse(view2), args1) Now I need view2 to only work if it's referred by view1. How do I do that? I did read it somewhere, not able to recollect @somefilter def view2(request): do something #view2 will only be referred from view1, else Http...

django combobox

ok so i`m makeing an app that has a file name field upload file field and a combobox, lets say I have smth like this for the combobox <select name="menu"> <option value="0" selected> select imp </option> <option value="1"> imp 1 </option> <option value="2"> imp 2 </option> <option value="3"> imp 3 </option> <option value=...

uwsgi + django import error

Hello, I have a problem when I use django with uwsgi with the pythonpath. I have a django project named 'project' which is the /sites/django/ directory So to start uwsgi i use this command : /opt/uwsgi/uwsgi -s 127.0.0.1:9001 -C -M 4 -t 30 -A 4 -p 4 -d /var/log/uwsgi.log --pythonpath '/sites/django/project/' --module wsgi If I am i...

WinPdb Error (Debugging Django) :CTimeoutHTTP instance has no attribute 'getresponse'.

I am trying to learn winpdb to debug django scripts. I have a very simply django web site that runs find if I start it from the command line, but when I try to launch it from winpdb it gives me this error message: RPDB2 - The Remote Python Debugger, version RPDB_2_4_6, Copyright (C) 2005-2009 Nir Aides. Type "help", "copyright", "licens...

Django: Set field choices from view?

I've got some <selects> that I need to populate with some choices that depend on the currently logged in user. I don't think this is possible (or easy) to do from inside the form class, so can I just leave the choices blank and set them in the view instead? Or what approach should I take? ...

Conditionally required fields and disabled inputs

My form has a bunch of address fields (street, city, country, province, postal code) that need to be filled out over and over again. To make it easier for the user, I've added a "copy from" selector where they can choose an address they've previously used. When they do this, the form fields are filled in automatically and then disabled. ...

Safe to modify settings.SITE_ID from middleware in Django?

I have modified the multihost.py middleware I found at http://effbot.org/zone/django-multihost.htm to set the settings.SITE_ID dynamically, but have some concerns that I may have just left the reservation. Most examples I have found for multiple domain hosting have been setup with multiple settings.py files hardcoded to their respective...

Is it possible to wrap the text of xticks in matplotlib in python?

Anyone know if it is possible to wrap the xtick labels in matplotlib? Right now I've got the following code (kind of messy -- been hacking at it for a while): def plotResults(request, question_id): responses = ResponseOption.objects.filter(question__id=question_id).order_by('order').annotate(response_num=Count('response')) counts = ...

On edit data from inlineformset_factory is missing

This is my code to get recipe data objRecipe = models.Recipe.objects.get(id=recipe_id) recipe = models.RecipeForm(instance=objRecipe) objRecipeSteps = models.RecipeStep.objects.filter(recipe__id = objRecipe.id) recipeSteps = models.RecipeStepFormSet(queryset=objRecipeSteps) I am able to display data from "recipe" but not from "recipe...

[Django] Doing a for loop within a template

I want to a do for loop like (for int x = 0; x < 3; x++) in a django template. How should I do it? Pseudo code looks like the following: {% for Summary in Summary_list %} {% ifchanged Summary.bu_id %} </tr> <tr> <td>{{Summary.bu.version}}</td> {% if Summary.platform_id != 1 %} ...

How should I represent a bit flags int field in django admin?

I have a data model with a bitfield defined something like this: alter table MemberFlags add column title varchar(50) not null default ''; alter table MemberFlags add column value integer( 3) not null default 0; insert into MemberFlags (title, value) values ("Blacklisted", 1), ("Special Guest", 2), ("A...

Exclude a field in django admin for users not super admin

Hi guys, how i'll exclude a field in django admin if the users are not super admin? thanks ...

Is there a way to modify the storage backend used by a Django FileField?

I am saving some uploaded files with a Django FileField set to use DefaultStorage backend. At some point after the file has been uploaded I'd like to move them to a different storage backend i.e. change the FileField's storage attribute (obv. after saving the contents of the source file to the new storage location). Simply changing the...

I have trouble installing the django-socialregistration app!

Hi, I'm a Django amateur, and have problems getting django-registration to work. I followed the installation instructions on their website, but for someone like me these instructions are not 100% clear as to what I should be doing. Here is what I've done: I installed the oauth2 and python-openid packages using pip. I then copied the f...

Anyone else having trouble keeping ghettoq running inthe background with django-celery?

nohup python manage.py celeryd -f queue.log 2>queue.err 1>queue.out & Handles one request fine, then the client app posting the next job to the queues fails with this traceback. tasks.spawn_job.delay(details) File "/releases/env/lib/python2.6/site-packages/celery/task/base.py", line 321, in delay return self.apply_async(args, ...