django

Simple Django form / model save question

I want to set the BooleanField inuse to True when I save the ModelForm (I'm using a form outside of the admin area) and I'm unsure how to do it. Models: class Location(models.Model): place = models.CharField(max_length=100) inuse = models.BooleanField() class Booking(models.Model): name = models.CharField(max_length=100, v...

Django update queryset with annotation

I want to update all rows in queryset by using annotated value. I have a simple models: class Relation(models.Model): rating = models.IntegerField(default=0) class SignRelation(models.Model): relation = models.ForeignKey(Relation, related_name='sign_relations') rating = models.IntegerField(default=0) And I want to awoid ...

How can I add the same object to a ManyToMany field ?

Hi! I need help on how to save the same (reference to an) object into a ManyToManyField. For example I have models like this: class Material(models.Model): name = models.CharField(max_length=50) class Compound(models.Model): materials = models.ManyToManyField(Material) In this example, the Compound can be made of one or many...

django order by date in datetime / extract date from datetime

I have a model with a datetime field and I want to show the most viewed entries for the day today. I thought I might try something like dt_published__date to extract the date from the datetime field but obviously it didn't work. popular = Entry.objects.filter(type='A', is_public=True).order_by('-dt_published__date', '-views', '-dt_writ...

Subdomains vs folders/directories

Hi all, I'm currently building a web application and I would like my users to have their own URLs to identify them. I could either do this using subdomains or using folders and am wondering what are the advantages and disadvantages of either one. I really like the folder solution because my URL mapping would be fairly easy. I have read...

Cleaning data which is of type URLField

I have a simple URLField in my model link = models.URLField(verify_exists = False, max_length = 225) I would like to strip the leading and trailing spaces from the field. I don't think I can do this in "clean_fieldname" or in the "clean" method. Do I need to sub-class the "URLField" and remove the spaces in to_python method? Is ther...

How do you avoid this race condition in Python / Django / MySQL?

I have a model MyModel that has a field expiration_datetime. Every time a user retrieves an instance of MyModel I need to first check if it has expired or not. If it has expired, than I need to increment some counter, update others, and then extend the expiration_datetime to some time in the future. So the view would do something ...

i18n Django Internationalization and database objects

I'm working in a bilingual project (es/en); for this project I've chosen to use django's i18n internationalization system (and I'm starting to regret it...) Today's problem is the following: for some models, my database stores information like description and es_description, or english_common_name and spanish_common_name (these are att...

"python manage.py runserver" = cannot execute binary file error (django)

new one to me commend I'm running ubuntu 10.04 relatively fresh install on my laptop manually installed django 1.2.1 when I try to run inside of a virtualenv python manage.py **any command** I get the error "bash: /home/alvin/workspace/storm-guard/virtual_damage_restoration/bin/python: cannot execute binary file " I have done the fo...

FormWizard: Forms determined dynamically

Hi, In my website, i wanna give users the possibility to upload videos, audio files, and pdfs. For this, i have thought about using formwizard. The first form-page is to ask for the name + the type of file to upload. The second form-page would be determined dynamically based on the answer of the first form. Is this possible with django's...

Django model form and objects database id

Hi I have a complex django object, which has properties of other class types. This gets like this: class Order: contractor - type Person some other fields.... In my form I'd like to be able to either choose existing Person object from the dropdown or add a new one with a form. I've managed to create forms and appropriate workfl...

Mac OS X: Trouble with Local Django + PyDev install working with remote MySQL

I've got PyDev installed in Eclipse. I'm trying to play with Django. I'm got a remote MySQL database set up. I would really like to not install MySQL on my MacBook. Trying to set up the MySQL plugin for python, I get (djangotest)jeebus:MySQL-python-1.2.3 blah$ python setup.py clean sh: mysql_config: command not found Traceback (most r...

Format date with month name in polish, in python.

Is there an out of the box way to format in python (or within django templates), a date with full month name in accordance to polish language rules? I want to get: 6 września 2010 and not: >>> datetime.today().date().strftime("%d %B %Y") '06 wrzesień 2010' ...

Django using mod_wsgi for Sub Urls

Similar questions have been asked before on this site, but I had a doubt as to how my site anchor tags will be replaced when I try to host my website under a suburl. E.g. My domain is www.example.com and my suburl which maps to the Django installation is www.example.com/2010/registration Now since the anchor tags in my templates (for th...

python mysql configuration problem

Hi all, I'm trying to make django work on snow leopard. So far I've installed mysql 64 bit installed python 2.7 64 bit and installed django 1.2.1. Now I'm trying to install mysql-python-1.2.3; at the beginning I had problems because I hadn't installed the setup tool, having done that when try to install it by executing these command pyt...

Django's HttpResponseRedirect() + reverse() truncating port number in URL

I run my local development server on port 8000 because my ISP blocks port 80. The problem is when using: return HttpResponseRedirect(reverse('foobar')) Django (for some reason) truncates the port from the URL - but it has no problem resolving it in the context of template tags e.g.: {% url foobar %}. Since I'm attempting to reduce th...

Django, save data from form without having to manually set each field to save ?

I can't seem to figure out a good way to do this, I have a bunch of form input fields and rather than having to do like below where I have to type out each fieldname = "" and such, is there a way to code this so it would automatically save each field from within the form? b = Modelname(fieldname=request.POST['fieldname']) b.save() I ...

Django / Python, using iteritems() to update database gives strange error: "dictionary update sequence element #0 has length 4; 2 is required"

I'm trying to do a Django database save from a form where I don't have to manually specify the fieldnames (as I do in the 2nd code block), the way I am trying to do this is as below (1st code block) as I got the tip from another S.O. post. However, when I try this I get the error "dictionary update sequence element #0 has length 4; 2 is ...

How to set an HTTP header for a JSON message from within a django-piston handler?

In a piston handler, I need to return a django.db.models.query.QuerySet as a proper JSON message (reflective of the underly model and query), while also adding an HttpResponse header of my own. So far, I can do one or the other, but not both (and get a proper looking JSON response). The below generates a proper JSON formatted response, ...

manage.py syncdb error while Django model using non-ascii verbose_name

Hi All, I am pretty new to Django. I want the name of my models to be displayed in Chinese, so i used verbose_name in my meta class of my model, codes below: #this models.py file is encoded in unicode class TS_zone(models.Model): index = models.IntegerField() zone_name = models.CharField(max_length=50); zone_icon = models...