django

Django: Exclude on a many-to-many relationship through a third table

I have a problem making "exclude" querys on tables which have a many-to-many relationship through a third table. I have a table with projects, a table with people and a relationsship table with the flags "is_green, is_yellow, is_red", like: class Project(models.Model): ... class Person(models.Model): projects = models.ManyToMan...

Can we append to a {% block %} rather than overwrite?

In my core.html I have a block labeled javascript. It would be great if I can append more lines to this block without overwriting everything in it. ...

Dynamically Display field values in Django template (object.x)

Hi Guys, I am currently working on an app that uses custom annotate querysets. Currently i have 2 urls setup, but i would need one for each field that the users would like to summarize data for. This could be configured manually, but it would violate DRY! I would basically have +-8 urls that basically do the same thing. So here is wha...

How do I strip a character in Django admin after submission before sending value to dB?

I'm more comfortable with PHP & MySQL, don't know a lick of Python (yet) except for the teeny tiny bit I picked up using the Django admin recently...therefore please excuse this very stupid question that I'm embarrassed to ask. In PHP this would be trivial for me... I'm using a color picker (farbtastic) w/ Django Admin, it's the only on...

Django: search (filter) by FileField.name

I need to find model instances whose FileFields point to a particular set of files. This is probably obvious and documented somewhere but I can't seem to find it: what's the syntax for using FieldField.name in a django filter query? Something like: models.MyModel.objects.filter(image__name='myfile.jpg') ...

Django + Postgresql -> unhandled exception.

I'm occasionally but quite often getting an unhandled exception in cursor.execute (django1.1/db/models/sql/query.py line 2369), using psycopg2 with postgresql. Looks like the database drops connection in some way, so Django crashes. For unhandled exception there is a ticket in Django's bugtrack (#11015), but I'm rather interested in re...

django management command + yui compressor

Can I call yui compressor: java -jar yuicompressor-x.y.z.jar [options] [input file] from a django management command and if so how do I go about doing it? I develop locally on Window and host on Linux, so this seem like a solution that will work on both. ...

Using keys with spaces

Is there a way to do something like the following in Django templates? {% for hop in hops%} <tr> <td>{{ hop.name }}</td> <td>{{ hop.mass }}</td> <td>{{ hop."boil time" }}</td> </tr> {% endfor %} The hop."boil time" doesn't work. The simple solution is rename the key boil_time, but I'm interested in alt...

Making transient (non-database) attributes in Django model available to template.

One of my models has attributes that are not stored in the database. Everything is fine at the view and model level but I cannot seem to display these 'non-database' attributes in my template. Here's some example code, an artificial example that mirrors the actual problem domain, to demonstrate the undesired behavior. The view: def o...

How to create a UserProfile form in Django with first_name, last_name modifications ?

If think my question is pretty obvious and almost every developer working with UserProfile should be able to answer it. However, I could not find any help on the django documentation or in the Django Book. When you want to do a UserProfile form in with Django Forms, you'd like to modify the profile fields as well as some User field. B...

How to serve stylesheet in Django

i want to use css in Django templates..If i give CSS with in the templates it gets working. But i want to use in static serve manner. settings.py DEBUG =True MEDIA_ROOT = 'C:/WorkBase/Python/first/static/' MEDIA_URL = '/static/' ADMIN_MEDIA_PREFIX = '/media/' TEMPLATE_DIRS = ( 'C:/WorkBase/Python/fi...

django - save a resize copy of image on upload (using admin site)

Hi - I'm building a site for a client that needs to support image uploads (an artist) through the admin interface. Since most of the images are pretty high-res, I wanted to create thumb copies of the image to display on the gallery page after the upload. The upload works great with the forms.ImageFile element, but I was looking for som...

Django upload_to outside of MEDIA_ROOT

My deployment script overwrites the media and source directories which means I have to move the uploads directory out of the media directory, and replace it after the upload has been extracted. How can I instruct django to upload to /uploads/ instead of /media/? So far I keep getting django Suspicious Operation errors! :( I suppose an...

django: time range based aggregate query

Hi there! I have the following models, Art and ArtScore: class Art(models.Model): title = models.CharField() class ArtScore(models.Model): art = models.ForeignKey(Art) date = models.DateField(auto_now_add = True) amount = models.IntegerField() Certain user actions results in an ArtScore entry, for instance whenever y...

Flexible pagination in Django

I'd like to implement pagination such that I can allow the user to choose the number of records per page such as 10, 25, 50 etc. How should I go about this? Is there an app I can add onto my project to do this? Thanks ...

Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like the following: On model load: SELECT AES_DECRYPT(fieldname, password) FROM tablename On model save: INSERT INTO tablename VALUES (AES_EN...

Django: Get all implementations of an Abstract Base Class

I have defined some models which look like this: class ABClass(models.Model): #common attributes class Meta: abstract = True class ConcreteClass1(ABClass): #implementation specific attributes class ConcreteClass2(ABClass): #implementation specific attributes class ModifiedConcreteClass1(ConcreteClass1): #implement...

Moving (very old) Zope/Plone Site to Django

I am ask to move data from a (now offline) site driven by Plone to a new Django site. These are the version informations I have: Zope Version (unreleased version, python 2.1.3 ) Python Version 2.1.3 (#1, Sep 19 2002, 13:15:46) [GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] CMFPlone (Installed product CMFPlone (1.0.1)) 2003-04...

I want to email users an encrypted file from a Django Backend Script on Ubuntu

I want to email users an encrypted file from a Django Backend Script (running through manage.py) on Ubuntu. How can I encrypt the data so that it is unreadable by 3rd parties who might intercept or even just read the email and will require a password string that I can supply to the end user via another method (not email.) What encrypti...

How to get two random records with Django

How do I get two distinct random records using Django? I've seen questions about how to get one but I need to get two random records and they must differ. ...