django

django IntegrityError: update or delete on table even though all references to object in question have been changed

When I try to delete a location through the django admin, there is a warning that lots of related items will be deleted. When I click to continue, I get the following error: Traceback (most recent call last): File "/mnt/hgfs/sftp/keg/dev/site/lib/django/core/servers/basehttp.py", line 651, in __call__ return self.application(envir...

How to call a static methods on a django model class during a south migration

I'm writing a data migration in south to fix some denormalized data I screwed up in earlier code. The way to figure out the right value for the incorrect field is to call a static method on the django model class. The code looks like this: class Account(models.Model): name = models.CharField() @staticmethod def lookup_by_...

Django form don't show specific inputs

Say, I've got a model like this: class Fleet(models.Model): user = models.ForeignKey(User) [...] ship1 = models.IntegerField(default=0) ship2 = models.IntegerField(default=0) ship3 = models.IntegerField(default=0) ship4 = models.IntegerField(default=0) And a form: class sendFleet(forms.Form): [...] shi...

Adding an error to a django form in a view... hack?

What I'm trying to do is to add an error for a field in a view, AFTER both form.is_valid() and form.save(), and it seems to work but only because of a hack, and I'm hoping someone here can explain why it works. So in my form's save() function, I connect to an LDAP server, and try to authenticate the user and password supplied in the for...

Problems with django deployment

Im trying to deploy my django and I always get one of these erros: (they alternate as I refresh the page) The model Page has already been registered ( its from feincms, but i dont get this on my computer ) unable to open database file (the database is sqlite3 and was successfully created with syncdb on the server ) Any ideas on what ...

how can I call view method in different files

If I have one view which called myview1.py and I want to call a view which is located in myview2.py, how can I do that? should I import myview2.py somehow? ...

Merging two git repositories together with Django web server, one developer.

Hi experts! I started my Django project locally and have been using git just fine. I got ahead of myself and copied the code to the server which instantly became out of sync with my local version. I hadn't done a branch or anything. The two part question is what's the best structure for me to work locally, push/pull to test server ...

Displaying properties in Django admin - translating their names

In my Django application my model has some values set as properties - they are calculated on demand from other values (like, min. value of some other objects' field, etc). This works pretty well as I don't need to store those in the database and the calculations can be expensive, so they're cached. So I have a model: class A(models.Mo...

Customizing UserCreationForm for email address as username in Django 1.2

Django 1.2 adds new allowable symbols to usernames, meaning usernames can simply be email addresses. Up until now I have been using the inbuilt UserCreationForm for registration - how can I alter it to label the 'username' field the 'email' field? And how also to add extra (but still User object) fields such as first and last names? (And...

Python and/or django solution for reading log files on linux?

I would like my Django application to be able to display local syslog etc files. I would like to avoid writing the logic for managing .1,.2 etc rotated files, and get an object for each log that I can retrieve a set of rows from. Is there any such python library, or even better, any such django app? Clarification: I don't want to writ...

Creating a user profile form in Django 1.2

Hi, I'm trying create a basic form which will allow the user to update their firstname, lastname and email as part of the User model. I've tried the following code: from django.forms import ModelForm from django.contrib.auth.models import User class BasicAccountForm(ModelForm): class Meta: model = User fields = ('f...

Why Django raw query is not working

Good people, I have installed djangoratings in my django project and i want to select records directly using raw sql from the djangoratings tables, i have followed the instruction given here but nothing seems to work. My code looks like this; def InsertRecord(): from django.db import connection, transaction cursor = connection....

another Django ImportError

Hi, I got ImportError while I try to import mercurial module into django app. This is part of Django debug page: ImportError at / No module named mercurial Python Path: ['/usr/lib/python2.5', '/usr/lib/python2.5/plat-linux2', '/usr/lib/python2.5/lib-tk', '/usr/lib/python2.5/lib-dynload', '/usr/local/lib/python2...

Django import error.

Hi. I have two django-apps. news and comments in news/models.py I import my comments with "from my_proj.comments.models import Comment" and in my comments/models.py I import my news class with "from my_proj.news.models import News" Then in my third app (named frontpage) I import News in the view.py. But I get the error: Could not impor...

django flatpages aren't working

My flatpages relevant options in the settings.py look like this: MIDDLEWARE_CLASSES = ( 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware', 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', ) INSTA...

Middleware to check existence of domain in Django

I have a single application which manages and delivers several sites. I does this by determining which domain to serve from the URL: http://myapplication.com/site_1/ or http://myapplication.com/site_2/ Each site obviously has it's own pages, so might end up with a url like this: http://myapplication.com/site_1/contact_us/ What I'd l...

use forloop.counter0 to index an array in Django

Hi, I am trying to access the contents of an array using forloop.counter0 in django templates but I can't get it working. What I have is {% for action in my_action_list %} {{another_list.forloop.counter0}} {% endfor %} Where my_action_list is a list and another_list is also a list. I have tried doing this manually e.g. {{anothe...

django dynamic FilePathField

class Project(models.Model): slug = models.SlugField(max_length=100) main_file = models.FilePathField(path="/home/mn/myfiles/%s" % slug) This code doesn't work, just illustrating what I'd like to do. I want to fill in FilePathField when object is accessed (ie. when it is updated in django admin, not when it's created). Is the...

join tables with django

queryObj = Rating.objects.select_related( 'Candidate','State','RatingCandidate','Sig','Office','OfficeCandidate').get( rating_id = ratingId, ratingcandidate__rating = ratingId, ratingcandidate__rating_candidate_id = \ officecandidate__office_candidate_id) This line gives me an error. I'm tryin...

Problem with Python logging RotatingFileHandler in Django website

I've a django powered website, and I use standard logging module to track web activity. The log is done via RotatingFileHandler which is configured with 10 log files, 1000000 byte each. The log system works, but this are the log files I get: -rw-r--r-- 1 apache apache 83 Jul 23 13:30 hr.log -rw-r--r-- 1 apache apache...