django

Activate virtualenv via os.system()

Hey all, I'm writing a Python-based shell script to boilerplate a Django app with virtualenv, pip, and fabric. Should be straightforward enough, but it appears that I'm not able to activate and run commands in the virtualenv through the shell script. os.system('virtualenv %s --no-site-packages' % project_name) os.system('source %s/bin/...

optimizing this django code?

Hi, I'm having some performance issues because I'm making a lot of query calls that I'm not sure how to reduce. user_item_rel_set is a m2m relation between user and items showing how much a user paid for a particular item. Each item can have multiple users and buyers, and I'm trying to get the m2m relation for a particular user. ...

Can Django admin handle a one-to-many relationship via related_name?

The Django admin happily supports many-to-one and many-to-many relationships through an HTML <SELECT> form field, allowing selection of one or many options respectively. There's even a nice Javascript filter_horizontal widget to help. I'm trying to do the same from the one-to-many side through related_name. I don't see how it's much dif...

How to implement Symfony Partials or Components in Django?

I've been developing in the Symfony framework for quite a time, but now I have to work with Django and I'm having problems with doing something like a "component" or "partial" in Symfony. That said, here is my goal: I have a webpage with lots of small widgets, all these need their logic - located in a "views.py" I guess. But, how do I...

Django: Ordering objects by their children's attributes

Consider the models: class Author(models.Model): name = models.CharField(max_length=200, unique=True) class Book(models.Model): pub_date = models.DateTimeField() author = models.ForeignKey(Author) Now suppose I want to order all the books by, say, their pub_date. I would use order_by('pub_date'). But what if I want a list of all a...

How can I get previous and next objects from a filtered, ordered queryset?

I have a page based on a model object, and I want to have links to the previous and next pages. I don't like my current solution because it requires evaluating the entire queryset (to get the ids list), and then two more get queries. Surely there is some way this can be done in one pass? def get_prev_and_next_page(current_page): ids...

Django: Signal on queryset.update

Django is sending the pre/post_delete signals if you are using the queryset.delete() method, but shouldn't it then also send pre/post_save on queryset.update()? ...

how to perform profiling for a website?

I currently have a django site, and it's kind of slow, so I want to understand what's going on. How can I profile it so to differentiate between: effect of the network effect of the hosting I'm using effect of the javascript effect of the server side execution (python code) and sql access. any other effect I am not considering due to t...

How do I do a if a in list_b test in Django 0.96 Templates?

How do I do a if a in list_b test in Django 0.96 Templates? I'm having a list of checkboxes and a variable containing a list of corresponding values from a previous submit of the checkboxes. Now I want to set all checkboxes in the list to checked="checked" and I usually use a "if a in listb" test for this. But this doesn't seem to be p...

YSlow Best Practices with Django apps, How to implement them?

Hi, I have an django 1.1.1 app, actually in developement, thinking in best practices I ran the YSlow test (Grade E Ruleset applied: YSlow V2 ) it recomends: Grade F on Add Expires headers -There are 37 static components without a far-future expiration date. Grade F on Use a Content Delivery Network (CDN) ...

Django: Filter rows containing a set of values in ManyToManyField

I have the following model: class Channel(models.Model): tags = models.ManyToManyField(Tag) class Tag(models.Model): name = models.CharField( primary_key = True) And want to get_or_create a channel that has exactly the given set of tags. tags = map(lambda x: Tag.objects.get(name = x), ['tag1', 'tag2']) channel = Channel.obje...

Problem with combined Authentication/Login view.

I have been using Django for several years now and up until this point have always redirected users to a login page after registering their account, and therefore have never had a problem of this sort. I am currently running Django v1.01 and on a new yet-to-be-released site have a combined registration/authenticate/login view which ...

How do I add a prefix to all urls and generically parse that as a kwarg

Let's say I have a site where all urls are username specific. For example /username1/points/list is a list of that user's points. How do I grab the /username1/ portion of the url from all urls and add it as a kwarg for all views? Alternatively, it would be great to grab the /username1/ portion and append that to the request as req...

Django App Not Showing up in Admin Interface

I'm currently moving from my development server to an Apache web production server. I've tried doing the following just by copying it over and I can login to the admin panel but it doesn't show up. My admin.py in my app looks like this: import models from django.contrib import admin admin.site.register(models.Organization...

How to set an event handler in a Django form input field

How to set a JavaScript function as handler in the event onclick in a given field of a Django Form. Is this possible? Any clue would be appreciated. ...

Reducing queries for manytomany models in django

EDIT: It turns out the real question is - how do I get select_related to follow the m2m relationships I have defined? Those are the ones that are taxing my system. Any ideas? I have two classes for my django app. The first (Item class) describes an item along with some functions that return information about the item. The second class...

Django form submit button's onclick does not call JavaScript function

I have a Django form that needs to do some client-side validation before submitting the form. This is the code in the template: <form action="/{{ blog_entry.id }}/addComment/" method="post"> {{ commentForm.name.label_tag }} {{ commentForm.name }} <span id="spanNameReq" style="color:Red; display:none;">Required</span> <br /> {{ com...

Weekly-based populating a database with the django admin

I'm building an small django app in order to manage a store employees roster. The employees are freelancers-like, they have weekly almost-fixed schedules, and may ask for extra ones at any weekday/time. I'm new to both python and django, and I'm using the django admin. Everything works fair enough (for me) when I "manually" add a "Turn...

Specific templates for flatpages in Django

Is it possible to link specific templates for different flatpages in Django? For example: /about/ -> templates/flatpages/about.html /contact/ -> templates/flatpages/contact.html This is what I have but all these pages point to the default.html template url(r'^(?P<url>about/)$', 'django.contrib.flatpages.views.flatpage'), ur...

Django on Apache with FCGI

Solved: Unfortunately I wasn't able to solve the problem but I started over and followed the Django + FastCGI guide on the "A Small Orange" wiki and everything is working as expected. I am trying to setup Django with FCGI on Apache. The web hosting plan that I am using is A Small Orange's shared hosting plan. Django is installed, worki...