django

Django - 2 fields unique together

Suppose, I want to record say poll choices by users everyday. In this case, i have a table named vote which has columns poll , choice and user-id . So how can i out the constraint (maybe in the django models or wherever possible) that poll and user-id both should not be the same for any entry but like the same user can vote for various d...

How can I make list or set translatable using gettext?

I have some structure in Python: > gender=( ('0','woman'), ('1','man') ) I want to translate it before I will display it in Django template. Unfortunately, below solution doesn't work: > from django.utils.translation import > ugettext_lazy as _ > > gender=( ('0',_('woman')), > ('1',_('man')) ) What shall I do to translate this? I ...

Django: How to override a related sets "add" method?

I am working on a django project and i want to send a signal when something get's added to some models related set, e.g. we have an owner wo has a set of collectables and each time the method owner.collectable_set.add(something) is getting called i want signal like "collectable_added" or something. signals are clear to me, but in which m...

Send emails in a django development environment on OS X leopard

Hay, i was wondering how i would go about setting up django so that i can send emails from a standard Leopard installation. In php i just use mail() and it sends the mail for me. Thanks ...

Cannot assign - must be a "UserProfile" instance

I have a class UserProfile defined which takes the default user as a foreign key. Now another class A has a foreign key to UserProfile. So for saving any instance in class A, how do i give it the userprofile object. Also, does making a class UserProfile mean that class user is still used and class UserProfile is just some other table?...

bundles in java?

in symfony 2.0 and django there are bundles that contain everything for a feature (html, css, js, img, php/python). so if you want to delete one feature, you basically just delete that bundle and unregister it from "main". are there java frameworks for this too? or is it different in java cause java is a compiling language. thanks ...

Django admin causes high load for one model...

In my Django admin, when I try to view/edit objects from one particular model class the memory usage and CPU rockets up and I have to restart the server. I can view the list of objects fine, but the problem comes when I click on one of the objects. Other models are fine. Working with the object in code (i.e. creating and displaying) is o...

Efficient query with Generic Relations

These are my models: class Comment(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField(_('object ID')) content_object = generic.GenericForeignKey() user = models.ForeignKey(User) comment = models.TextField(_('comment')) class Post(models.Model): title = models....

Get the current URL within a django template

Hay, i was wondering how to get the current URL within a template. Say my URL was /user/profile/ How do i return this to the template? Thanks ...

Django | passing form values

I want to create a user sign up process that requires two different forms with the same data one (1st form) is for filling out the data and other one (2nd form) is for displaying the filled data as a summery (before actually saving the data) so then user can view what he/she has filled up... my problem is that how do I pass 1st form's da...

pdb is not working in django doctests

So I created the following file (testlib.py) to automatically load all doctests (throughout my nested project directories) into the __tests__ dictionary of tests.py: # ./testlib.py import os, imp, re, inspect from django.contrib.admin import site def get_module_list(start): all_files = os.walk(start) file_list = [(i[0], (i[1], ...

Django: query spanning multiple many-to-many relationships

I've got some models set up like this: class AppGroup(models.Model): users = models.ManyToManyField(User) class Notification(models.Model): groups_to_notify = models.ManyToManyField(AppGroup) The User objects come from django's authentication system. Now, I am trying to get all the notifications pertaining to the groups that the...

Django: need help with keeping apps from depending on one another

I'm working on a site that will help private teachers manage their students, and part of this will be keeping track of how much money the teacher is owed. I want my apps to be reusable and free from dependency on one another. So, I've created one app whose responsibility is the CRUD of student, teacher, and parent objects (these models ...

Left Join with a OneToOne field in Django

I have 2 tables, simpleDB_all and simpleDB_some. The "all" table has an entry for every item I want, while the "some" table has entries only for some items that need additional information. The Django models for these are: class all(models.Model): name = models.CharField(max_length=40) important_info = models.CharField(max_lengt...

Django select max id

Hi, given a standard model (called Image) with an autoset 'id', how do I get the max id? So far I've tried: max_id = Image.objects.all().aggregate(Max('id')) but I get a 'id__max' Key error. Trying max_id = Image.objects.order_by('id')[0].id gives a 'argument 2 to map() must support iteration' exception Any help? ...

Django forms I cannot save picture file

i have the model: class OpenCv(models.Model): created_by = models.ForeignKey(User, blank=True) first_name = models.CharField(('first name'), max_length=30, blank=True) last_name = models.CharField(('last name'), max_length=30, blank=True) url = models.URLField(verify_exists=True) picture = models.ImageField(help_text...

Django Interrupted system call when sending email

Hi, Sometimes, when submitting a form (pretty much any form on my site that sends me an email), I get the following error: File "/usr/lib/python2.5/smtplib.py", line 603, in starttls (resp, reply) = self.docmd("STARTTLS") File "/usr/lib/python2.5/smtplib.py", line 378, in docmd return self.getreply() File "/usr/lib/python2.5/...

What exactly is a web application framework?

I'm getting into python for cgi and came across Django. I'm not quite sure I understand it very much. Is it something I have to install inside apache or is it just something I can use with my cgi? Wanted to know because I'd love to learn it but my server I'm using doesn't give me a lot of privileges. thanks ...

Is there a way to get direct_to_template to pass RequestContext in django?

I have found myself writing the same view over and over. It is basically this: def home_index(request): return render_to_response('home/index.html', RequestContext(request)) To keep with the dry principal, I would like to utilize a generic view. I have seen direct_to_template, but it passes an empty context. So how can I use a g...

Adding custom fields to users in django

I am using the create_user() function that Django provides to create my users. Also I want to store additional information about the users. So I tried following the instructions given at http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users but I cannot get it to work for me. Is there a step-by-s...