django

Django: how to upgrade from 1.1 to 1.2?

Does anyone know how to / can anyone link to simple instructions for how to upgrade from Django 1.1 to Django 1.2? I can find masses of documentation on the differences between them, the changes you'll need to make to your project etc. What I can't find is actually how to upgrade! Thanks. ...

How do I make an XHRDataSource request to a Django server in YUI?

I'm using post, and the YUI documentation example code isn't working. YAHOO.util.Event.addListener(window,"load",function() { var columnDefs = [ {key:"url", sortable:true, resizeable:true}, {key:"title", sortable:true, resizeable:true}, {key:"count", sortable:true, resizeable:true} ]; this....

Extending South Introspection in Django

I have a custom app which I wanted to start using South with. It uses a FK for associating a blog entry from another app (proprietary, not written by me). Problem is when I try to run the initial schemamigration I get an error that some of the blog entry app's fields cannot be frozen. The fields that can't be frozen are fields that us...

Getting current url

I have a couple of views which are rendering the same template and I have some {% url %} tags into that template which needs to point to different location based on the current view. Is there any context variable which gives the name of the view(for named urls), like view-1 view-2, so in my template I can use it like this: {% url url-na...

How to filter a template tag?

I've got a tag that looks like this: {% partial "partials/vehicleform.html" vehicle=vehicles.empty_form %} Which just renders an empty form. But now I want to pass the output of that to the escapejs filter so that I can use it in a JavaScript variable. How can I do that? ...

Django permission_required error message?

I've added this decorator to one of my views @permission_required('codename') When a user visits that page and doesn't have the required permissions, he is redirected the login page, but it doesn't really tell him why he's been redirected there. Worse yet, if he logs in, and still doesn't have the permissions, he's going to be complet...

Django not generating "selected='selected'" for html select list representing a booleanfield

Please excuse the long code, but the question itself is short. Using Django 1.2.1 with MySQL Server version: 5.1.37 with mysqldb 1.2.2 on Python 2.5 For the model QUALIFICATION_TYPE_CHOICES = ((1, 'WGH'), (2, 'PQR')) class Qualification(models.Model): name = models.CharField(max_length=50) qualification_type = models.PositiveS...

django handling images and other media content

I am learning Django, using the django book, which is great. However, it is a little down on using the django test server to serve up image files and other media. Obviously, any page has some amount of image content beyond the straight up HTML that you put in templates. And there are various other files that need to be served up such as ...

Get ID of total_form_count?

When using a formset, you need to add {{formset.management_form}} to your form. This renders 3 fields, one of which is TOTAL_FORM_COUNT. I want to get the ID of this field so that I can modify its value via JS. How can I do that? I'm trying stuff like formset.management_form.TOTAL_FORM_COUNT and .fields.TOTAL_FORM_COUNT to get the field...

What's the difference of ContentType and MimeType

As far as i know, they are absolute equal. However, browsing some django docs, i've found this piece of code: HttpResponse.__init__(content='', mimetype=None, status=200, content_type='text/html') wich surprise me the two getting along each other. The official docs was able to solve the issue in a pratical manner: content_type is a...

Why does formset.empty_form contain errors and forget initial values?

formset.empty_form is great for generating a blank form that I can use in my JS. However, once the form has been posted, empty_form suddenly contains error messages and it magically forgets all its initial values. Why is that? Instead, I have to do this stupid hack to get an actually empty form empty_form = MyFormSet().empty_form Reg...

how to add ajax onto django admin

Hi all, I'd like to make some aspects of django admin interface a bit more fluid without refreshes. For example, I have this ReportAdmin(admin.ModelAdmin) class, which has a list_editable property that will allow user to edit the specific fields right on the list of reports view rather than clicking into each report and edit it there....

MVC2 - Are There Signals for Models?

I'm just starting on my first ASP.NET MVC project (it's actually extending an existing MVC project that uses 4.0 and Linq2SQL). What I'm looking for is a way to create an instance of a model every time a different model is created (i.e., saved to the database). I see an OnCreated() method in the generated code, but that's in a partial cl...

Can I have a jquery AJAX image Picker to use it as a RTE plugin

now i am developing a django-based blogging system. and am stuck when trying to integrate textarea with a fully-featured Rich Text Editor, tiny-MCE and CKEditor implemented their image browser (Image Manager) plugin using PHP (with a complex-not-documented source code). and when i was googling i found that there was a good free example...

Passing instance/default value to a ModelFormSet for the empty forms to use, in a view.

How do i pre-populate the exclude fields in a ModelFormSet. AuthorFormSet below doesn't take an instance argument here, only queryset. So how do i force the empty forms coming in not to have a NULL/None user attribute. I want to be able to set that user field to request.user models.py class Author(models.Model): user = models.Forei...

Implementing separate incrementing primary keys in Django

I am developing an internal app on the side for the company I work for, and am wanting to use Django in order to learn it and Python in general, however I've hit a bit of a snag with the PKs. I'm trying to emulate a part of the current application where 2 MySQL tables, TaskCategory and Tasks, handle the tasks that need doing. Every Task...

Django sitemaps with no associated object (just a view)

Hi, I'm setting up some Django sitemaps. It works really well for all the objects I have, but I'm curious about how I should do it if I'd like to put something in the sitemap that has no object associated with it. For instance, I have a category listing, and I can just return a queryset of all categories. URLs would be example.com/cats...

"Best" way to conditionally display the values of different model fields in Django templates?

I'm building a site which will provide product information in two languages: English and Chinese. Each product must have an English name, and may also have a Chinese name. Each time a product page is requested, the request object is inspected to determine whether the product's name should be displayed in English or Chinese. In the latt...

Checking FieldFile on django form

beginner question. here's pdb output (Pdb) entry.image <FieldFile: None> (Pdb) entry.image is None False how do I check if the image exists or not? Lets say I want to access entry.image.file but I dont know whether entry.image exists SOLVED check my own answer ...

Django: Lowercasing filename of the input Image File

I have a model: class Foo(models.Model): poster = models.ImageField(u"Poster", upload_to='img') I'm using the admin to upload posters and save Foo objects. I now need to find a way to lowercase the filename before save. For instance POSTER.png or Poster.png or poster.PNG should be lowercased to poster.png. What would be the easie...