django

Strange behavior with ModelForm and saving

This problem is very strange and I'm hoping someone can help me. For the sake of argument, I have a Author model with ForeignKey relationship to the Book model. When I display an author, I would like to have a ChoiceField that ONLY displays the books associated with that author. As such, I override the AuthorForm.init() method and I c...

In Django admin, can I require fields in a model but not when it is inline?

In django admin, there are fields I'd like to require if a model is being edited standalone. If it is inline, I don't want them to be required. Is there a way to do this? ...

For the django admin, how do I add a field to the User model and have it editable in the admin?

Heyas I'm trying to understand the django admin better and at the same time, I'm trying to add one more field to the current user admin. In models.py I've done User.add_to_class('new_field', models.BooleanField(default=False)) and in admin.py I've got the following (with fieldsets basically just copied from django/contrib/auth/admin...

Django with system timezone setting vs user's individual timezones

How well does Django handle the case of different timezones for each user? Ideally I would like to run the server in the UTC timezone (eg, in settings.py set TIME_ZONE="UTC") so all datetimes were stored in the database as UTC. Stuff like this scares me which is why I prefer UTC everywhere. But how hard will it be to store a timezone ...

Custom Python exception with different include paths

Hi, Update: This is, as I was told, no principle Python related problem, but seems to be more specific. See below for more explanations to my problem. I have a custom exception (let's call it CustomException), that lives in a file named exceptions.py. Now imagine, that I can import this file via two paths: import application.exception...

how to use french letters in a django template?

I have some french letters (é, è, à...) in a django template but when it is loaded by django, an UnicodeDecodeError exception is raised. If I don't load the template but directly use a python string. It works ok. Is there something to do to use unicode with django template? ...

How to debug the MySQL error message: Caught an exception while rendering...

I am building Django +MySQL on dreamhost, but met the error messages: Caught an exception while rendering: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') ORDER BY tag.used_count DESC, tag.name ASC' at line 1") I traced hard and found the ...

What is the best way to add an API to a Django application?

I am adding MetaWeblog API support to a Django CMS, and am not quite sure how to layer the application. I am using django_xmlrpc, which allows me to map to parameterised functions for each request. It is just a case of what level do I hook in calls to the django application from the service functions (AddPage, EditPage etc) For django-...

Formatting a variable in Django and autofields

Hi...I have this problem I've been trying to tackle for a while. I have a variable that is 17 characters long, and when displaying the variable on my form, I want it to display the last seven characters of this variable in bold...how do I go about this...I'd really appreciate anybody's insight on this. ...

Auto increment a value in Django with respect to the previous one

Is there a way to autoincrement a field with respect to the previous one...e.g if the previous record has the value 09-0001, then the next record should be assigned 09-0002 and so one...ideas? I'm thinking of overriding the save method, but how exactly I'm not so sure ...

Django ORM equivalent

Hi all, I have the following code in a view to get some of the information on the account to display. I tried for hours to get this to work via ORM but couldn't make it work. I ended up doing it in raw SQL but what I want isn't very complex. I'm certain it's possible to do with ORM. In the end, I just want to populate the dictionary a...

Export set of data in different formats

I want to be able to display set of data differently according to url parameters. My URL looks like /page/{limit}/{offset}/{format}/. For example: /page/20/0/xml/ - subset [0:20) in xml /page/100/20/json/ - subset [20:100) in json Also I want to be able to do the same for csv, text, excel, pdf, html, etc... I have to be able to se...

django ifequal

Hi, I need to make a links section for a django project that show only the non active links, ie. if i'm at home, the section only shows the about link and not the home link. Im using something like this in my template: {% ifequal item.url request.path %} <a href = "{{item.url}}" > {{item.name}} </a> {% endifequal %} it works fine bu...

Applying DATABASE_OPTIONS when testing Django project (or make it to use InnoDB for MySQL)

As the title says, I want to apply DATABASE_OPTIONS settings when I run my tests via ./manage.py test. In django/db/backends/creation.py, it does not consider this option at all in both create_test_db() and _create_test_db(). This breaks a test with a view that uses transaction.rollback function with InnoDB. It seems that test databases...

What are some interesting features of the EveryBlock.com source code?

The source code behind EveryBlock.com, a major Django-powered website founded by Adrian Holovaty, one of the co-Benevolent Dictators For Life of the Django framework, was recently open-sourced. The source is available as tarballs and on github. This large body of code from an originator of Django should have some interesting features, p...

How to use multiple databases in a django applicaion

Hi There, I need to connect to multiple databases in my django application. I want to make connections to all the databases when ever i start the application and use those connections for all the requests. But I did not understand how to do that (setting these databases connections in global environment). I tried to set database connec...

how to check internal database structure

I am new to django (and have no experience in SQL), so maybe there is no standard way of doing this. So assume I use the band,person,membership example from http://docs.djangoproject.com/en/dev/ref/contrib/admin/#working-with-many-to-many-intermediary-models What if I want to make sure, there is at max one membership bertween a fixed p...

Using SimpleXMLTreeBuilder in elementtree

I have been developing an application with django and elementtree and while deploying it to the production server i have found out it is running python 2.4. I have been able to bundle elementtree but now i am getting the error: "No module named expat; use SimpleXMLTreeBuilder instead" Unfortunately i cannot upgrade python so im stuck ...

Skip steps on a django FormWizard

I have an application where there is a FormWizard with 5 steps, one of them should only appear when some conditions are satisfied. The form is for a payment wizard on a on-line cart, one of the steps should only show when there are promotions available for piking one, but when there are no promotions i want to skip that step instead of ...

Django way to do conditional formatting

What is the correct way to do conditional formatting in Django? I have a model that contains a date field, and I would like to display a list of records, but colour the rows depending on the value of that date field. For example, records that match today's date I want to be yellow, records that is before today I want green and ones afte...