django

Modify default queryset in django

I have added a 'cancelled' field to my model, is there a way to modify the model default query to something like cancelled=False ? without having to modify all my filter/exclude queries ? ...

Django URL regex question

Hey all! I had a quick question about Django URL configuration, and I guess REGEX as well. I have a small configuration application that takes in environments and artifacts in the following way: url(r'^env/(?P<env>\w+)/artifact/(?P<artifact>\w+)/$', 'config.views.ipview', name="bothlist"), Now, this works fine, but what I would like ...

Django - provide additional information in template

Hi all, I am building an app to learn Django and have started with a Contact system that currently stores Contacts and Addresses. C's are a many to many relationship with A's, but rather than use Django's models.ManyToManyField() I've created my own link-table providing additional information about the link, such as what the address typ...

Popularity Algorithm - SQL / Django

Hi folks, I've been looking into popularity algorithms used on sites such as Reddit, Digg and even Stackoverflow. Reddit algorithm: t = (time of entry post) - (Dec 8, 2005) x = upvotes - downvotes y = {1 if x > 0, 0 if x = 0, -1 if x < 0) z = {1 if x < 0, otherwise x} log(z) + (y * t)/45000 I have always performed simple orderin...

onmouseover with django / imagekit

I'm using Imagekit. View.py includes: def pics(request): p = Photo.objects.all() return render_to_response('Shots.html', {'p': p}) The following simple code in the template will generate associated images: {% for p in p %} <img src = "{{ p.display.url }}"> <img src = "{{ p.thumbnail_image.url }}"> {% endfo...

I am currently serving my static files in Django. How do I use Apache2 to do this?

(r'^media/(?P<path>.*)$', 'django.views.static.serve',{'document_root': settings.MEDIA_ROOT}), As you can see, I have a directory called "media" under my Django project. I would like to delete this line in my urls.py and instead us Apache to serve my static files. What do I do to my Apache configs (which files do I change) in order to...

Extracting fixture for one specific object

I want to extract the necessary code to recreate a set of Models from my production environment to my testing environment. There is something wrong in the data that causes an Exception, and I need the data in my local environment to do debugging. I looked at django-extensions and the dumpscript command is almost what I want. But I have ...

Passing context between templatetags, django

Hi overflowers, I am using django to create a web-application. I have created a template in where I load a templatetag. In this templatetag i load another templatetag. From the template I pass context to the first templatetag, but the context is not available from the second templatetag (inside the first templatetag) - see below. I ho...

Django Custom Admin

Hello there Currently I have an app with a save method in its models.py . So I would like to change this so the models does not do the save() method, but rather have a separate view that will do this in die admin site. Can you please direct me in the correct direction? Thank you ...

Django: request object to template context transparancy

Hi! I want to include an initialized data structure in my request object, making it accessible in the context object from my templates. What I'm doing right now is passing it manually and tiresome within all my views: render_to_response(...., ( {'menu': RequestContext(request)})) The request object contains the key,value pair which i...

Django parallel arrays in a template

I have 2 arrays that I would like to render in a template, one is the data to be output, the other is a formset for deleting items. since it seems django does not support boolean operators in the template tag, I have tried packaging the items, but they return the first item and the first form in 2 rows only. How does one package such i...

Please help my learning in Django

Hi All I am new on Django and python.I want to wirte program with Django .So please share me useful ideas and concept.How can I set up djanog in my window OS. I little confuse and occur some errors while I read ebooks. Share me with all experiences please in step by step. Thank for all ...

Defining the context of a word - Python

Hi folks, I think this is an interesting question, at least for me. I have a list of words, let's say: photo, free, search, image, css3, css, tutorials, webdesign, tutorial, google, china, censorship, politics, internet and I have a list of contexts: Programming World news Technology Web Design I need to try and match wo...

Globally accessible object across all Celery workers / memory cache in Django

Hi everyone, I have pretty standard Django+Rabbitmq+Celery setup with 1 Celery task and 5 workers. Task uploads the same (I simplify a bit) big file (~100MB) asynchronously to a number of remote PCs. All is working fine at the expense of using lots of memory, since every task/worker load that big file into memory separatelly. What I ...

Show models.ManyToManyField as inline, with the same form as models.ForeignKey inline

I have a model similar to the following (simplified): models.py class Sample(models.Model): name=models.CharField(max_length=200) class Action(models.Model): samples=models.ManyToManyField(Sample) title=models.CharField(max_length=200) description=models.TextField() Now, if Action.samples would have been a ...

Django: order by count of a ForeignKey field?

This is almost certainly a duplicate question, in which case apologies, but I've been searching for around half an hour on SO and can't find the answer here. I'm probably using the wrong search terms, sorry. I have a User model and a Submission model. Each Submission has a ForeignKey field called user_submitted for the User who uploaded...

Programmatically specifying Django model attributes

Hi! I would like to add attributes to a Django models programmatically. At class creation time (the time of the definition of the model class). The model is not going to change after that in run time. For instance, lets say I want to define a Car model class and want to add one price attribute (database column) per currency, given a lis...

django: how to interconnect various logical pieces of a webpage

Hi, everyone. I'm just starting with django, so sorry for a possibly stupid question. Imagine, I have a webpage with 3 logical pieces: content, dynamic menu, banners. It seems ok to me to have a template with something like: {% include "banners.html" %} {% include "menu.html" %} {% include "content.html" %} But then, how do I do it? ...

Using forloop.counter value as list index in a Django template

Hi, in my Django 1.1.1 application I've got a function in the view that returns to his template a range of numbers and a list of lists of items, for example: ... data=[[item1 , item2, item3], [item4, item5, item6], [item7, item8, item9]] return render_to_response('page.html', {'data':data, 'cycle':range(0,len(data)-1]) Inside the...

PermanentTaskFailure in AppEngine deferred library.

I am using App Engine and the deferred library. But every once in a while my task fail with the following error: Permanent failure attempting to execute task Traceback (most recent call last): File "/base/python_lib/versions/1/google/appengine/ext/deferred/deferred.py", line 256, in post run(self.request.body) File "/base...