django

Make Django forms use comma as decimal separator

I am writing a Django app for use in a country where they use comma as decimal separator. I have a model that contains a django.db.models.DecimalField, and I use model forms. How can I make the resulting form field render using comma and accept comma back from the user? Following the advice of jweyrich, I have upgraded my application ...

Images are not being stored?? - Django

Hi folks, These are my following settings: MEDIA_ROOT = '/home/webapps/test_project/media/' MEDIA_URL = 'http://192.168.0.2:8090/site_media/' ADMIN_MEDIA_PREFIX = '/media/' These are my model fields: large = models.ImageField(blank=True, null=True, upload_to="images") thumb = models.ImageField(blank=True, null=True, upload_to="image...

Django script add field to database

I added a slug field to my database and now need to go through and add those. I want to run a script that looks at the slug field in the database and if empty generates and saves. Here is what I thought was along the lines, but is not working. from project.apps.tracks.models import * def process_slug(): if not track.slug: ...

Django how to set main page

hello, i want to set a main page or an index page for my app. i tried adding MAIN_PAGE in settings.py and then creating a main_page view returning a main_page object, but it doesn't work Also, i tries to add in the urls.py a declaration like (r'^$', index), where indexshould be the name of the index.html file on the root (but it obvio...

Django: How to access modelform field data in templates

I have a page which displays a form that a logged-in user can use to edit their profile. The first time the user loads the corresponding view, with a GET request, the form should display the values of the users existing profile record. Because I'd like to have granular control over the markup used for the form fields, I'd like to retri...

Django: How do I use a different form_class with django-registration

I want django-registration (version 0.8) to use my custom form rather than the default one. However, I want to continue to use the default django-registration view. What should the rest of the line below look like to achieve this? (r'^accounts/register'...), I've tried this below but get a syntax error: (r'^accounts/register/$', ...

What is a way to handle database connection failure in Django 1.2?

What is a way to handle database unavailability and redirect queries from unavailable slave to another one in Django 1.2? Btw, i found out, that it was discussed: http://code.djangoproject.com/wiki/MultipleDatabaseSupport#Requirements (see "Transparently handling database failure") UPD> I use PostgreSQL backend (probably will use pg po...

How to have 2 different admin sites in a Django project?

Hi, I want to have 2 separate admin sites inside a Django project. By separate I mean - they should have separate users authentication, they should administer different models, and have different looks and URLs. The reason I want to do it is the customer wants separate section to administer the CMS part of the page, and separate to ...

Django TextField max_length validation for ModelForm

Hi, Django does not respect the max_length attribute of TextField model field while validating a ModelForm. So I define a LimitedTextField inherited from the models.TextField and added validation bits similar to models.CharField: from django.core import validators class LimitedTextField(models.TextField): def __init__(self, *arg...

Django: Can I restrict which fields are saved back to the database using forms?

I have a form that I use to display several fields from a record to the user. However, the user should not be able to update all the fields that are displayed. How do I enforce this? It would nice if I could specify which fields to save when calling form.save, but I couldn't get this to work. Here's some of the code: obj = get_object_or...

how do i set my python path for success with my import statements?

I'm trying to install djangobb and when running manage.py syncdb it returns with Traceback (most recent call last): File "manage.py", line 2, in <module> from django.core.management import execute_manage ImportError: No module named django.core.management I know that deep in my python installation there is django/core/managemen...

(Django) Ajax form submit with jquery-forms.

I'm trying to add ajax form submit to my webpage. Form will add user's email to newsletter. I've found this solution : http://www.tutorialswitch.com/web-development/quick-and-simple-ajax-forms-with-json-responses/ and now I'm trying to rewrite it for django. So I have my form, included on main page : <div id="form-newsletter-messa...

Django regex field - unique and without blank spaces

Hello, i have a ModelForm, in which i'm having a CharField, which is declared as unique in the Model. But I have 2 problems: 1.If i fill in the form with a field having the same name i don't get an error message 2.I'd like this field not to contain white spaces Is it possible to do that using a ModelForm? Thanks a lot! ...

How do I change the value of submitted form data using form object and redisplay it?

Essentially I want to sanitize some data a user submits in a form when I redisplay it if there is an error. This is easy to do if I am extracting the data from a form object. I can override the clean() method and manipulate the data. I can also set the .initial value for the first time it is displayed. However, I cannot find a way of...

Django: How do I get every table and all of that table's columns in a project?

I'm creating a set of SQL full database copy scripts using MySQL's INTO OUTFILE and LOAD DATA LOCAL INFILE. Specifically: SELECT {columns} FROM {table} INTO OUTFILE '{table}.csv' LOAD DATA LOCAL INFILE '{table}.csv' REPLACE INTO {table} {columns} Because of this, I don't need just the tables, I also need the columns for the tables. ...

Accessing Actual Objects with ResultSet Hit objects returned from index search on Djapian

I want to be able to have an actual list of objects returned when I query, instead of a ResultSet with Hit objects. Example: indexer.search(word).prefetch() this would return a ResultSet object with matching hits, but I would like to have access to the objects themselves. Similar to what: model.objects.filter(name__icontains=word) ...

How to get the formatted POST data of a Django form?

I have a Django ModelForm but don't want the user to click on a reguar submit button. Instead, I made my own submit button and will post the form data using Ajax/jQuery. The data to post is a mix of the form data plus other information I gather on my UI. But... how do i get the formatted POST data the html form was supposed to submit? If...

Using Python Image Library with VirtualEnv on Windows.

I'm attempting to install the PIL library in an Virtual Enviroment that I have created. Usually to install PIL I'd grab the install, however this won't allow me to choose my virtualenv only my root Python folder (C:/Python26). I tried both pip install PIL and easy_install PIP but they didn't work. I've also tried downloading the TAR, e...

How can I refactor this django query to not select each individual object?

Here's my view: def rsvp_list(request, id, template="rsvp/rsvp_list.html"): rsvp = RSVP.objects.get(id=id) return render_to_response(template, { 'attendees': rsvp.attendee_set.all().order_by('email__first_name'), }, context_instance=RequestContext(request)) and here's my template: {% for attendee in attendees %...

Value from one view's form to other view

Can I perform in django such operation, that in one view I assign a value of return from other view, that renders its own form template and basing on it returns value ? (So in other words if on this form rendered by the other function user clicks ok, I return true, and if user clicks cancel I return false) Sample code : Main function: ...