django

[Django] Custom authentication backend functions in some cases, not always

I am using a custom authentication backend built on CAS and LDAP in a Django project. I intend to have it set up such that it can get permissions based on the what LDAP groups a user is part of. However, I have had problems with it and took a step back, so that both has_perm and has_module_perms in my backend return True always. What I ...

Why can't Python find my path? (django)

import sys sys.path.append('/home/myuser/svn-repos/myproject') from myproject.settings import * But, it says module not found when I run the script? By the way, settings.py has been set up and manage.py syncdb works. ...

Why am I getting this error in Django?

I have a script that imports a models.py from an app, but it will not import! I don't believe I am supposed to manually create an "export DJANGO..." environment variable...I'm doing something else wrong. Traceback (most recent call last): File "parse.py", line 8, in ? from butterfly.flower.models import Channel, Item ...

Django ORM: Optimizing queries involving many-to-many relations

I have the following model structure: class Container(models.Model): pass class Generic(models.Model): name = models.CharacterField(unique=True) cont = models.ManyToManyField(Container, null=True) # It is possible to have a Generic object not associated with any container, # thats why null=True class Specific1(Gen...

How to defer a Django DB operation from within Twisted?

I have a normal Django site running. In addition, there is another twisted process, which listens for Jabber presence notifications and updates the Django DB using Django's ORM. So far it works as I just call the corresponding Django models (after having set up the settings environment correctly). This, however, blocks the Twisted app, ...

Django Custom Managers for User model

How would I go about extending the default User model with custom managers? My app has many user types that will be defined using the built-in Groups model. So a User might be a client, a staff member, and so on. It would be ideal to be able to do something like: User.clients.filter(name='Test') To get all clients with a name of Test...

Django field required in a clean method in a form class

I want to redefine the required attribute for a field in a clean method of my form file: class NewUserFullForm(NewUserForm): REGEX_PHONE = '^(\+[0-9]{2})[ \.\-]?[0-9][ \.\-]?[0-9]{2}[ \.\-]?[0-9]{2}[ \.\-]?[0-9]{2}[ \.\-]?[0-9]{2}$' phone = forms.RegexField(REGEX_PHONE, help_text='Ex : +33 1 34 12 52 30') fax = forms.RegexField(REGEX_...

Django 1.1 forms, models and hiding fields

Consider the following Django models: class Host(models.Model): # This is the hostname only name = models.CharField(max_length=255) class Url(models.Model): # The complete url url = models.CharField(max_length=255, db_index=True, unique=True) # A foreign key identifying the host of this url # (e.g. for http://w...

Passing a pre_delete() or post_delete() signal arguments ?

I am using signals to perform an action after an object has been deleted; however, sometimes I want to perform a different action (not the default one) depending on an arugment. Is there a way to pass an argument to my signal catcher? Or will I have to abandon the signal and instead hard code what I want to do in the models ? What I...

Customising Install location for Django (or any Python module)

I'd like to to install Django into a custom location, I've read the distutils documentation and it suggests that I should be able to do something like the following to install under my home directory (when run from an unpacked django tarball). > python setup.py install --home=~/code/packages/install --install-purelib=modules --install-p...

django queryset: how to order by a (backwards) related field?

Hi folks! In this situation I have two models, Comment and Score. The relationship is defined in the Score model, like so: class Comment(models.Model): content = TextField() ... class Score(models.Model): comment = models.ForeignKey(Comment) value = models.IntegerField() My question is: How do I construct a queryset ...

Django tagging migration to GAE

I have a Django app that use a django-tagging. I need to port this application to GAE. So, the main problem is to migrate tagging part. It has a complicated model, that should be rewritten to work with Google store. I think tagging is very popular django app and someone has the same problem before. Has someone a rewritten model? ...

Django form not saving default image name

I've got a form which includes the option to upload an image. In my model, I've defined a default image name to use when no image is selected for upload. When selecting a file, the form uploads the file to my media directory and properly places the filename in the db field (working as it should). When not selecting a file, that field ...

Concurrency control in Django model

How do I handdle concurrency in a Django model? I dont want the changes to the record being overwritten by another user who reads the same record ...

Django db reset without loading fixtures

Is there an easy way to reset a django database (i.e. drop all data/tables, create new tables and create indexes) without loading fixture data afterwords? What I want to have is just an empty database because all data is loaded from another source (a kind of a post-processed backup). I know that this could be achieved by piping the out...

Django ModelForm: accessing a field's value in the view template

Q: Is it possible to pull out the value for one of my ModelForm's fields while in the template? If so, how? Background: I have a search form that I'm using to allow users to filter down query results. And, the table of results, along with the form can, be exported to an Excel sheet. When the page is rendered w/ the new results, the inpu...

Django Template For Loop Over request.META Dictionary

I am trying to loop over a dictionary, specifically the request object's meta property. It is a dictionary, but the following code is treating it like it is a list of strings. How can I do this correctly? EDIT: I found that if I replace request.META with request.META.items, this works, but why does the following not work? Is it not a di...

Django: Extending Querysets / Connect multiple filters with OR

Hi! I have to work with a queryset, that is already filtered, eg. qs = queryset.filter(language='de') but in some further operation i need to undo some of the already applied filtering, eg not to take only the rows with language='de' but entries in all languages. Is there a way to apply filter again and have the new parameters connected ...

Django Year/Month based posts archive

Hello, i'm new to Django and started an application, i did the models, views, templates, but i want to add some kind of archive to the bottom of the page, something like this http://www.flickr.com/photos/ionutgabriel/3990015411/. So i want to list all years and next to them all the months from that year. The months who have posts to ...

How to ensure database changes can be easily moved over DVCS using django

Overview I'm building a website in django. I need to allow people to begin to add flatpages, and set some settings in the admin. These changes should be definitive, since that information comes from the client. However, I'm also developing the backend, and as such will am creating and migrating tables. I push these changes to the hu...