django

looking for ideas on how to force order of pictures in a gallery (django app)

Hi - I'm building a django app that has an image gallery, and the client insists the images be displayed in specific order. I use the admin interface to upload the images and edit their properties, and I have an ImageFile class in my model that basically looks like this: class ImageFile(models.Model): """represents an image file""" ...

How do I import the render_to_response method from Django 1.1 inside of Google App Engine?

I'm a Python newbie, so I'm sure this is easy. Here's the code in my main.py: import os os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' from google.appengine.dist import use_library use_library('django', '1.1') # Use django form library. from django import forms from django.shortcuts import render_to_response The last line breaks...

what is attr 'gtbfieldid' and how to avoid autocomplete behavior ?

Hi, I have this simple form: class PagoDesde(forms.Form): from django import forms as f desde = f.DateField(input_formats=['%d/%m/%Y']) In my template: {{ form.desde }} And has associated a jqueryui.datepicker in the document.ready $("#id_desde").datepicker(); The html result is: <input type="text" id="id_desde"...

Dynamic variables in Django base.html

I have an app that uses flatpages and other constructs that don't take a request object. This causes problems in base.html. Here's a simple example. If I wanted something like "Welcome {{ request.user.username }}!" at the top of every page, what's the best way to make that happen? ...

How can I limit the available choices for a foreign key field in a django modelformset?

Application: This is a workshop proposal system for a conference. A user can create presenters and workshops, and link them together. Each user should only have access to the presenters and workshops that s/he created/owns. # Models: class Workshop(models.Model): name = models.CharField(max_length=140, db_index=True) presenter...

Allow / in django url

I want to make a wiki, and i must assign for each url a view. Each url can contain letters (A-Z, a-z), digits and punctuation ('.', ',', '/', '-', '_'). How can i make the expression ? I want something like this : (r'^(?P<wiki_page>\w+)/$', 'www.wiki.views.page') but this works only for letters, digits and '_'. ...

Python: Behavior of the garbage collector

I have a Django application that exhibits some strange garbage collection behavior. There is one view in particular that will just keep growing the VM size significantly every time it is called - up to a certain limit, at which point usage drops back again. The problem is that it's taking considerable time until that point is reached, an...

What is the best location to put templates in django project?

What is the best location to put templates in django project? ...

Django / Automatically retrieve models names

Hi, I'd like to retrieve automatically, in a loop, the names of the models located in a specific Django app inside my project. Does someone know how to do that ? Best Regards Guillaume ...

How do I convert a django QuerySet to numpy record array?

How do I convert a django QuerySet to numpy record array? PS: I know you can iterate and construct it and but is there any other cleaner solution? ...

Django: provide choices list to a checkbox from a view function

Hi, in my Django application I've got a form with a ChoiceField that normally allows to choice between a range of integer values. class FormNumber(forms.Form): list=[] for i in range(1, 11): list.append((i,i)) number=forms.ChoiceField(choices=list, initial=1) Now I need to override the default choices list from a view method in some ...

Adding new custom permissions in Django

I am using custom permissions in my Django models like this: class T21Turma(models.Model): class Meta: permissions = (("can_view_boletim", "Can view boletim"), ("can_view_mensalidades", "Can view mensalidades"),) The problem is that when I add a permission to the list it doesn't get added to the auth...

Django Admin - Re-authentication?

I'm in a bit of a dilemma at the moment regarding Django's admin backend. The default authentication system allows already logged-in users that have staff privileges to access the admin site, however it just lets them straight in. This doesn't feel “right” to me, and I'm wondering if it would be difficult to at least require a re-authen...

Calling Method from Different Python File

As I'm currently learning Django / Python, I've not really been using the concept of Classes, yet. As far as I'm aware the method isn't static.. it's just a standard definition. So let's say I have this Package called Example1 with a views.py that contains this method: def adder(x,y): return x + y Then I have an Example2 which also...

Django ordered ManyToManyField in admin interface

I have a legacy database with tables for documents and authors. A third table defines an ordered many to many relationship between the documents and authors, using foreign keys to the documents and the authors and an integer to specify the author order for a given document. Using Django 1.1.1 (or SVN), is there a way to edit the documen...

How to sort model by values in a dictionary?

In Django, I have a model, and I will have a dictionary having the id's of objects in this model as keys, and a weight as values. I would like to use these weights in an order_by: MyModel.objects.filter(title__icontains=query).order_by( 'value_from_the_dictionary' ) How to make this work? I can't put the weights in the model, as they...

How can I pass a User model into a form field (django)?

Basically, I need to use the User's password hash to encrypt some data via a custom model field. Check out the snippet I used here: Django Encryption. I tried this: class MyClass(models.Model): owner = models.ForeignKey(User) product_id = EncryptedCharField(max_length=255, user_field=owner) ......................................

Filtering records by incrementing parameters in Django

I've been able to implement a filtering solution for my app...so far I have filtering by year, make and body style for a vehicle inventory. What I want to do is to filter the record this way: Lets assume I choose Acura in make, in the resultant page, if I choose one of the other filters i.e. year or body style, I'll need only the recor...

Django Admin: OneToOne Relation as an Inline?

I am putting together the admin for a satchmo application. Satchmo uses OneToOne relations to extend the base Product model, and I'd like to edit it all on one page. It is possible to have a OneToOne relation as an Inline? If not, what is the best way to add a few fields to a given page of my admin that will eventually be saved into the...

Does Django cache templates automatically?

I'm new to Django and trying to implement a voting system between two images. However, it looks like the page is being cached or something because when I refresh it, some values are wrong. I have no cache setup in my Settings. Here is the View: def rate(request, type): photos = Photo.objects.order_by('?')[:2] c = Context({"ph...