django

Django & Apache: How to debug on Testing server

I am trying to debug an issue that happens on our testing server. So how do I make it so that I can access our testing server when I start Django by typing: python manage.py runserver ? Does it have to pass through Apache? If so, I need to configure Apache somehow but I am not using mod_wsgi and so, don't know how to do this. Thanks!...

Spooky Custom Template Filter?

Hi Folks, I was having trouble trying to iterate on a template on two dimensions at the same time. The basic situation is explained here: http://www.djangobook.com/en/2.0/chapter04/ ( in the apples, bananas indices example ) >>> from django.template import Template, Context >>> t = Template('Item 2 is {{ items.2 }}.') >>> c = Contex...

Modify Django user delete method?

If I go to the Django admin page and delete a user, I want it to run some code before/after it deletes the user. I know about overriding models' delete() methods, but I'm not sure how to apply it to a built-in model. Also, I'd like to be able to do it without 'subclassing' the User model and creating a (for instance) MyUser model. Is t...

Django cannot find url pattern in URLConf although it is defined

I type the following url in my browser: http://localhost:8000/en/weblog/2010/aug/10/wie-baue-ich-ein-weblog/ an I get a "Page Not Found (404)" error, although the 10th entry (r'^weblog/(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/(P?<slug>[-\w]+)/$', 'django.views.generic.date_based.object_detail', entry_info_dict), in my URLCon...

Django: Proxy Meta-class ignoring verbose_name_plural

Django-admin is pluralizing a model that I have running as a proxy class. The normal case here works fine: class Triviatheme(models.Model): [ ... elided ... ] class Meta: db_table = u'TriviaTheme' verbose_name_plural='trivia themes' But for a main content table, I have a parent model called 'Content', and a p...

Django: Caching aggregate query?

I've got an Invoice model, and I want to keep the total up to date. So I've added a property like this @property def item_total(self): if not hasattr(self, 'item_total_cache'): self.item_total_cache = self.items.aggregate(t=Sum('amount'))['t'] return self.item_total_cache Because item_total might get called a few times...

Django internationalization with i18n: choosing language in template using jQuery

For the internationalization of my django project, I'm using django's i18n, and I love it. For setting the language in the template, instead of using forms like in this example : <form action="{{site_url}}i18n/setlang/" method="post"> <input name="next" type="hidden" value="" /> <select name="language"> {% for languag...

Resuable model members in django

I have a django model like this: class Something(models.Model): title = models.CharField(max_length=200, default=u'') text = models.CharField(max_length=250, default=u'', blank=True) photo = models.ImageField(upload_to=u'something') def photo_thumb(self): if self.photo: return u'<img src="%s" />'...

Django unique constraint + form errors

I'm having some issues with double-posting on my site. I figure a simple unique constraint across all the relevant fields will solve the issue on a database level, but then it just produces a nasty error page for the user. Is there a way I can turn this into a pretty form error instead? Like a non_field_error? Or what approach should I t...

In django 1.2.1 how can I get something like the old .as_sql?

In past versions of django you could construct a queryset and then do .as_sql() on it to find out the final query. in Django 1.2.1 there is a function ._as_sql() which returns something similar, but not the same. In past versions: qs=Model.objects.all() qs.as_sql() ====> SELECT `model_table.id`, `model_table.name`, `model_table.size`...

Is it possible to combine annotations with defer/only in django 1.2.1?

I have two simple models: Book, and Author Each Book has one Author, linked through a foreignkey. Things work normally until I try to use defer/only on an annotation: authors=Author.objects.all().annotate(bookcount=Count('books')) that works. The query looks like: select table_author.name, table_author.birthday, COUNT(table_book.i...

Django custom template filter can't work

I have an errror: 'run_target' is not a valid tag library: Template library run_target not found, tried django.templatetags.run_target I don't know why it can't work, even i add 'db.templatefilters' it can't work too... Can anyone help me? thank you :) Below is my file structure: db/ models.py templatefilters/ __init__...

postgresql full text search query to django ORM

Hi, I was following the documentation on FullTextSearch in postgresql. I've created a tsvector column and added the information i needed, and finally i've created an index. Now, to do the search i have to execute a query like this SELECT *, ts_rank_cd(textsearchable_index_col, query) AS rank FROM client, plainto_tsquery('famille age')...

Django programming Training Course

I would like to know if anybody in here knows some excellent opportunities to learn Django web programming in an e.g. intense 2 week programming course. Anywhere on the world. Preferably in the Bay area. Any suggestions would be greatly appreciated. Thanks for the time! ...

Django cannot find my inherited comment form

Guys, Am trying to modify the look of django comments template form on my site but in vain. I have created a comments folder on my project template folder(myproject/template/comments/) and copied the form.html & preview.html from django/contrib/comments/template/comments/). I have then modified my local comment form.html according to ...

How do I set default field value to value of other field in a Django model?

If I have the following model in django; class MyModel(models.Model): name = models.CharField(max_length=50) fullname = models.CharField(max_length=100,default=name) How do I make the fullname field default to name? As it is right now, the fullname defaults to the string representation of the name CharField. Example: new ...

Django: What are the best practices to migrate a project from sqlite to PosgreSQL

I need to migrate a complex project from sqlite to PostgreSQL. A lot of people seems to have problem with foreign keys, data truncature and so on... Is there a full automated utility ? Do I need to check some data or schema before the migration ? Edit : I tried django-command-extensions DumpScript but it doesn't run on my 2GB RAM PC...

Django Bulk Zip upload

Hi there I want to upload images to a gallery app. I want the user to be able to either load images normaly, or upload on zip file containing all the images for that gallery. Then it must be uncompressed and all images must be added to that model. This is for the admin site. Any ideas? ...

django 1.1 creating high temporary tables with mysql 5.1

Hi, we are using django 1.1/mysql5.1 for one of our projects. Seems like as the load on the webserver(apache/mod-wsgi) increases, the number of temporary tables created on mysql also increases, causing heavy alerts on our monitoring infrastructure. To give you an example, when the number of connected clients increases from 100 - 300, the...

django orm and 3 relations

Hi, I have a problem to transpose my sql request in the orm. Well, this my sql request : SELECT DISTINCT accommodation.id from accommodation LEFT JOIN product on product.accommodation_id=accommodation.id LEFT JOIN date on date.product_id = product.id WHERE date.begin> '2010-08-13'; So i want all the accommodations for a period, wit...