django

Django: outcommenting in templates

How can lines in a template be outcommented or otherwise be disabled (short of deleting the line)? E.g. if file "base_weblog.html" contains: {% load ProgramVersion %}{% render_month_links %} How can this line be hidden at runtime? This does not work (e.g. TemplateSyntaxError if ProgramVersion is not a valid tag library - that is ...

Django : What gets executed as the server starts? As a request comes in?

I've been doing some class hacking in Django. And I call my changes from settings.py as I figure this runs before anything else. However, I've just come across a situation where this doesn't work for me. So, is there another place after settings.py, which I can guarantee will always be run by the server before it starts handling any req...

Conditional Django Middleware (or how to exclude the Admin System)

Hi all, I want to use some middleware I wrote across the whole of my site (large # of pages, so I chose not to use decorators as I wanted to use the code for all pages). Only issue is that I don't want to use the middleware for the admin code, and it seems to be active on them. Is there any way I can configure the settings.py or urls.p...

Django Paginated Comments .. is there any existing solutions?

Hi, is there any existing pagination solution for Django contrib.comments? What I need is just a simple paginated django comments, for the Basic Blog application (from the Django Basic Apps) I used, using a simple has_previous and has_next I have copied the django.contrib.comments and tried modify the code but with no success. The code...

Same Table Django ORM Soft Delete Method Okay?

Hello, I'm using the following setup to implement soft deletes in Django. I'm not very familiar with Django under the hood so I'd appreciate any feedback on gotchas I might encounter. I'm particular uncomfortable subclassing a QuerySet. The basic idea is that the first call to delete on a MyModel changes MyModel's date_deleted to t...

Django ORM: filter by a list of objects

I have the following code to put all my users from a multichoice field into a list USERS = [] for user in User.objects.filter(groups__name='accountexec'): USERS.append((user.id,user)) I need to use Log.objects.filter() to get all the logs with a user= to a user in the USERS list ...

Defining "global variable" in Django templates

I'm doing something like: {% extends 'base.html' %} {% url myapp.views.dashboard object as object_url %} {% block sidebar %} ... {{ object_url }} ... {% endblock %} {% block content %} ... {{ object_url }} ... {% endblock %} Django documentation says url templatetag can define a variable in context, but I don't get any value for objec...

Race conditions in django

Here is a simple example of a django view with a potential race condition: # myapp/views.py from django.contrib.auth.models import User from my_libs import calculate_points def add_points(request): user = request.user user.points += calculate_points(user) user.save() The race condition should be fairly obvious: A user can...

Django Debug toolbar - Prototypejs version

I am a big fan of Django Debug Toolbar But what happened is it totally has got Jquery framework being used for all its UI richness. But my application uses Prototypejs. So browser is actually getting confused to execute(or not executing) a couple of methods written by me. So how do I get pass this? ...

How to make a Django ImageField save the image to another model?

I have a member profiles application that stores simple information about members of a team. Part of the profile is an image to be used as an avatar. I've been using Photologue to create standard galleries of photos, but it has an ImageModel that can be extended to take advantage of Photologue's resizing and caching functionality. The...

login_required decorator and urlresolver.reverse() in Django

I have several views with @login_required decorator. And I'm going to use django.core.urlresolvers.reverse() function for redirection to them. I wrote in urls.py: urlpatterns = ('myapp.views', '^(?P<key>[-a-zA-Z0-9]+)/some-operation/$', 'some_operation'), ) and in views.py: return HttpResponseRedirect( reverse('myapp.views....

Python/Django or C#/ASP.NET for web development?

Hi, I am a .NET developer. I have no experience on Python. Which platform is more scalable? Which platform is more suitable for large-size high-traffic web sites? If you have any experience about scalability on these platforms, please inform us. Thank you. ...

form validation in django

In which file or form should validation code be written ? ...

How do I convert a currency (accuracy is secondary) from a static currency (say USD) for a web app (Django Framework)?

Hi, I am writing a web app based on Django, and I hope to pick many of the good brains here on how I might be able to convert a price based on 1 static currency (say USD), to any other currencies? Is there some feed or something I can parse to convert it on the fly? Thanks. ...

python class attribute inheritance

I am trying to save myself a bit of typing by writing the following code, but it seems I can't do this: class lgrAdminObject(admin.ModelAdmin): fields = ["title","owner"] list_display = ["title","origin","approved", "sendToFrames"] class Photos(lgrAdminObject): fields.extend(["albums"]) why doesn't that work? Also since t...

Display a boolean model field in a django form as a radio button rather than the default Checkbox.

This is how I went about, to display a Boolean model field in the form as Radio buttons Yes and No. choices = ( (1,'Yes'), (0,'No'), ) class EmailEditForm(forms.ModelForm): #Display radio buttons instead of checkboxes to_send_form = forms.ChoiceField(choices=choices,widget=forms.RadioSelect) class Me...

Confused about lookup in a table

I have a table of person and a table of events. I want to find a person in a dropdown, select that person and then display all events for that person. I am confused about what commands to use. I get a lot of syntax errors. Any help will be appreciated Thanks ...

Per-session transactions in Django

I'm making a Django web-app which allows a user to build up a set of changes over a series of GETs/POSTs before committing them to the database (or reverting) with a final POST. I have to keep the updates isolated from any concurrent database users until they are confirmed (this is a configuration front-end), ruling out committing after ...

Using django_extensions reset_db command with postgres

I'm having some trouble getting the reset_db command extension to work with my postgres database. I get an error "psycopg2.OperationalError: cannot drop the currently open database" which looks like the same issue reported here. I'm using django 1.0 and django_extensions 0.4.1, which I believe has the fix for the above issue included. S...

Django Apache Redirect Problem

I'm configuring my Django project to run on Apache using mod_wsgi. I am attempting to run Django below the directory 'cflow' on apache, but am running into problem with redirects. My apache conf looks something like this: ... WSGIScriptAlias /cflow "C:\Program Files\Apache Software Foundation\Apache2.2\wsgi\django.wsgi" <Directory "C:\...