django

Django Form Template Button

Django accepts and works with form button in format: <input type="submit" value="Submit" /> How to make it to work with the following: <button type="button">Submit</button> ...

Limit number of characters with Django Template filter.

I am trying to output the first 255 characters of a description on a list of items and am looking for a method to get that. Example: I have a variable that contains 300 or so characters. I call that variable like this, {{ my_variable|characterlimit:255 }} and it would return only the first 255 characters of that variable. If this tag...

Where can I save a variable to be used between calls to a Django view?

I am looking to return a random number between 0 and 4 in a Django view, which is repeatedly called. The number is limited in that it can't be the same as the number that was called previously. It would be fine if the number loops rather than being random, it just can't be the same as what was returned before. I tried using a variable o...

How to rename a foreignkey field with South ?

Renaming a simple charfield etc seems easy (http://stackoverflow.com/questions/3235995/django-how-to-rename-a-model-field-using-south) However when I try using the same on a ForeignKey field I get an error: _mysql_exceptions.OperationalError: (1091, "Can't DROP '[new_fkey_field_name]'; check that column/key exists") Which stems from...

Django Registration Number of users logged in

I have an application where I would like to display the number of users that are logged into the system. Im trying to determine the cleanest way to do this that will not create a large load on the system. I know that the system keeps track of the "last logged in time" So I could do a query and aggreate the number of users whose last log...

Django admin - process field before database insert / update

I have a django model with a text field. I'm using a rich text editor (nicEdit) on the admin site to allow the client to easily enter markup into the field. I'd like to process the contents of the field and perform a few actions before anything is inserted into the database. For example, I want to strip junk generated by MS Word, font t...

What is the best way to flag a model as inappropriate/spam in Django?

I am new to Django and in my webapp I'd like the user to be able to flag a model as inappropriate. I've been using reuasable apps like django-voting and tagging but there is not much documentation for django-flag. Suggestions? ...

How do I design my models with "interchangeable" fields?

Sorry about the title, I couldn't find the right word. I'll try my best to describe it properly. I have a business model which needs some properties. But the properties of the business depends on what category it is. So for example, I have a business named "XYZ" under the category "Restaurant" and a business named "ABC" under the cate...

processing an image upload form in django: when to use save() vs chunks() vs cleaned_data?

I have successfully uploaded an image using the following code: views.py from django.conf.urls.defaults import * from django.http import HttpResponse, HttpResponseRedirect from django.shortcuts import render_to_response from django import template from django.template import RequestContext from mysite.uploadr.forms import UploadFileFo...

"invalid literal for int() with base 10:" But can't see why it is accessing an integer

Hi, I can't see why in my application i am getting this error. As all primary keys are text fields are integers. Here is my code: forms.py class EventAttendForm(forms.Form): talk = forms.ModelChoiceField(queryset=Talk.objects.all()) membersAttended = forms.ModelMultipleChoiceField(queryset=Member.objects.all()) models.py ...

django Queryset with year(date) = '2010'

Hi there, I'm trying to build this query select * from m_orders where year(order_date) = '2010' the field order_date is a DateTime field. I just don't want to use raw sql queries here. Is it even possible to use e.g. MySQL functions in django quersets? ...

ImportError: No module named django.core.handlers.modpython

Django was installed via apt-ger on Ubuntu. sudo apt-get install python-django Need development version for new features. Removed previous installation via sudo apt-get purge python-django Re-installed Django following this article http://jeffbaier.com/articles/installing-django-on-an-ubuntu-linux-server/ django-admin.py --versi...

Django unique_together doesn't work with ForeignKey=None

I saw some ppl had this problem before me, but on older versions of Django, and I'm running on 1.2.1. I have a model that looks like: class Category(models.Model): objects = CategoryManager() name = models.CharField(max_length=30, blank=False, null=False) parent = models.ForeignKey('self', null=True, blank=True, help_text=_('The di...

how to access the request in a django custom authentication backend?

I want to do the following with django's authentication: Log incorrect log-in attempts Temporarily lock accounts after 'x' number of incorrect log-in attempts Log successful log-ins. I thought a custom auth backend would be the solution. I can do most of what i want, but I want to log the IP and REMOTE_HOST of the user making the at...

How to allow download of file via Apache with Django's permission?

Is there a way for Apache to allow or deny a file download after checking with Django for permission? That is, I want the user to have a permission within Django to determine if the user has the rights to a file. And, if the user has the permission, Apache would start the file download. Or, if the permission is not set for that user, th...

Problem setting up django on Apache

This is probably really simple. But I guess I'm too new to WSGI and Django to get it on my own. I have a brand new shiny Django project on a Ubuntu virtual machine hosted in /var/www/mysite. The project was created with django-admin startproject mysite I'm following a WSGI tutorial to get it set up, so I created an ./apache folder...

FormWizard and saving data

Hi guy's, im trying to use django formWizard, all is fine, but im getting an error in the last step after submit Traceback (most recent call last): File "/home/vacantes/webapps/django/lib/python2.6/django/core/handlers/base.py", line 100, in get_response response = callback(request, *callback_args, **callback_kwargs) File "/h...

Deployment woes: What do I do after "svn up"?

I've got several questions. I have no idea how the heck to deploy... After doing "svn up" on my production server, I'm not sure how to "refresh" my server so that the changes are reflected when you visit it. What can I do to refresh my server to see the changes in production? (I tried rebooting.) I also noticed that some of the files t...

Django: better to save a slug to the DB or generate dynamically, if used for lookup?

So this is almost a duplicate of this question, except that I do want to use the slug for lookup. My URLs look like this: http://url.com/county/place-name The unique combination of 'county' and 'place-name' is used to look up the database object, except that 'place-name' is stored in the database as 'Place Name'. So if I don't stor...

Django app to retrieve data from other apps models?

I have an app name sync which has a form created from a model that saves itself. I want to create another app called activity that retrieves the data from the sync models and other future apps. How can I do that in the activity views app? This is my sync models.py from django.db import models from django.contrib.auth.models import User...