django

unicode error when saving an object in django admin

Hello, In my django app, I have some objects that cause the corresponding URL in the django admin to be non ascii. (for example: http://mysite/admin/myapp/myclass/Présentation/) I can edit the object without any problem but when I save it I have the following error: UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in p...

Django dynamic number of filter for a objects request

Hello How can I do something like this : products_list = Product.objects.all() for key in keywords: products_list = products_list.filter(name__icontains=q) This don't work. Thank you for your help ...

why my code error? I copied the 'memoize' function in django.utils.functional

my code: a=[1,2,3,4] b=a[:2] c=[] c[b]='sss'#error memoize function: def memoize(func, cache, num_args): def wrapper(*args): mem_args = args[:num_args]#<------this if mem_args in cache: return cache[mem_args] result = func(*args) cache[mem_args] = result#<-----and this return re...

How would you allow users to extend off a Django site for templating purposes?

I'm building a Django site, and like a blog, I'd like users to further extend the content off the site by "skinning" through templates. I'd like to re-use Django templating for this, I've been brainstorming on this but haven't gotten a solid idea how I can do this, can I hear some of your brilliant suggestions? Thanks! ...

django custom tags with template blocks?

Hi, I just started learning about custom tags in django and was wondering if there was a feature that allowed the injection of data as if they were blocks/tags. The real problem is this, tags work great, but lets say my tag is some html and javascript, does that mean I have to call two tag functions and inject them into the page that ...

Django, create_user giving error, manually creating user gives different error

Working with Django 1.1 on Python 2.6.4, trying to execute the following: user = User.objects.create_user(username, email, password) The three values are from form.cleaned_data, and have already been validated. i get this error: 'dict' object has no attribute 'strip' Traceback: File "/usr/lib/pymodules/python2.6/django/core/handlers/...

Is it possible to create an end-user facing site using Django admin alone?

I'm very new to Django, having never developed on it. I'm trying to develop a site which has functionality exposed only to authenticated users (typical enterprise thing: for this discussion, let's say it's a private blogging platform). The functionality I'm looking for is: Users can create a new blog. each user can belong to multip...

How to start doing TDD in a django project?

Hi, all. I have read a lot of essays talking about benifits TDD can bring to a project, but I have never practiced TDD in my own project before. Now I'm starting an experimental project with Django, and I think maybe I can have a try of TDD. But what I find now is that I don't even know how to answer the question "what should I put in...

Django: How should I store a money value?

I'm running into a paradigm problem here. I don't know whether I should store money as a Decimal(), or if I should store it as a string and convert it to a decimal myself. My reasoning is this: PayPal requires 2 decimal places, so if I have a product that is 49 dollars even, PayPal wants to see 49.00 come across the wire. Django's Decim...

Difficulty getting flup fcgi script to work

I'm building a site for a client using django. It's been hosted on shared hosting and mod_wsgi can't be used. In the old year, I got it working using fcgi, but when I got back, it was broken. I have replaced the fcgi script with a simple hello world script: #!/usr/bin/python def myapp(environ, start_response): start_response('200 O...

Django Query Question

I'm trying to query an object and when I hard code the value it works but when I use a variable for it the query doesn't work. Here's the class: class AdvertisementType(models.Model): type = models.CharField(max_length='40') description = models.CharField(max_length='80') def __unicode__(self): return '%s' % self.t...

Debugging livelock in Django/Postgresql

I run a moderately popular web app on Django with Apache2, mod_python, and PostgreSQL 8.3 with the postgresql_psycopg2 database backend. I'm experiencing occasional livelock, identifiable when an apache2 process continually consumes 99% of CPU for several minutes or more. I did an strace -ppid on the apache2 process, and found that it w...

Sort by display name instead of actual value

Consider this sample model: MODEL_CHOICES = ( (u"SPAM", u"Spam"), (u"XOUP", u"Eggsoup"), ) (snip) type = models.CharField(max_length=4, choices=MODEL_CHOICES) (The actual implementation is domain-specific and in non-English, so this sample has to do.) When building my query, I'd like to sort the results by that...

Django Accesing Model Class From Field Instance

I have some code that is passed on instance of a CharField. Is there any way I can figure out what model class this field belongs to? ...

What's the difference between quantize() and str.format()?

I don't mean what's the technical difference, but rather, what's the faster/more logical or Pythonic, etc. way to do this: def __quantized_price(self): TWOPLACES = Decimal(10) ** -2 return self.price.quantize(TWOPLACES) or def __formatted_price(self): TWOPLACES = Decimal(10) ** -2 return '{0:.2...

POST request returns back to admin index page with "You don't have permissions to edit anything"

I am overriding the admin index.html template by adding at the end: <h1>Exporting and Validating Users</h1> {% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %} {% if export_message %} <p><strong>{{export_message}}</strong></p> {% endif %} <table> <tr> <td> <form action=...

django sort query result by occurrence count

I've got the flowing two models: class Item(models.Model): Name = models.CharField(max_length = 32) class Profile(models.Model): user = models.ForeignKey(User, unique = True) ItemList = models.ManyToManyField(Item, related_name = "user_itemlist") For Item X I want to get a list of Item objects present in ItemList for all...

Custom Django template tag to look up a string username and return it as a user object.

I use some third-party template tags in my Django Application (maintained elsewhere) that return a username as a string I can access in my templates like this. {% for user in gr.user.foll.list %} {{user}} Trouble is because {{user}} is returned as a string - I need to convert into a Django User Object, if it exists in the Django DB,...

Python/Django: If 5 and 5.00 are different values (when expressed in Decimal), then...

If 5 and 5.00 and 5.000 are all different, then why does Django's decimal field save without the .00 even when I have decimal_places=2 ? More importantly, how can I save a value 5.00 as 5.00 in Django without using String. ...

Creating several profile classes in django

I'm getting started with django and I'd like to extend the basic django.contrib.auth.models.User class to create my own site profile(s). Here is described how to do it, got that. As far as I've understood it, you can only specify a single class as AUTH_PROFILE_MODULE in your settings.py. Now, if I create an extension class of my profil...