django

Python - Overwriting __getattribute__ for an instance?

Hi! This one seems a bit tricky to me. Sometime ago i already managed to overwrite an instance's method with something like: def my_method(self, attr): pass instancemethod = type(self.method_to_overwrite) self.method_to_overwrite = instancemethod(my_method, self, self.__class__) which worked very well for me; but now I'm trying t...

Problem using jQuery clone function in form

Those snippes of code that you will check works fine for FF, Chrome, Safari, but seems to be a problem with IE when running jQuery clone function: My template: <form method="post" action="/post/add/"> {{ form.management_form }} <div class='table'> <table class='no_error'> <input id="id_mypost_set-0-title" type="text" ...

Rendering a ManyToMany Field

I'm trying to display a manytomany field in my template, but all I get is a blank...I'm displaying it as below: {% for vehicle in vehicle.features.features %} <li>vehicle.features</li> {% endfor %} My model is as follows: class Vehicle(models.Model): stock_number = models.CharField(max_length=6, blank=False) vin = models.Cha...

what is the easiest way to set a default choice for a django select widget?

I have a model that has a foreign key relation to another. I'd like to have the dropdown that is produced by widget=forms.Select have a default value ...

upload field of an invalid form points to nowhere

This may be a question with a very simple answer, however I couldn't come across to one on the internet. I am writing a Django application. I have a form with an unrequired ImageField. After the user has submitted the form (with an image), if the form is invalid, on the serverside I populate the form with the request data and files (eg:...

Separating ManyToManyFields in a template

Following my question at link text I'd like to separate the features in the template using categories such as Interior, Exterior, Mechanical etc. I'm trying out the code below, but apparently it's not giving me what I want. {% for feature in vehicle.features.all %} {% ifequal vehicle.features.type.type "Interior" %} <li>{{ feature...

Multiple filters on a data

I want have have multiple filters on the data. like first i want to filter by date field and then by type field and then by some other field .... as many times as possible. i must pass on the field and value in the url and it must apply the filter and pass the data to the next filter. ...

Any way to hack FogBugz On demand to SSO?

I will launch soo a new iPhone app and want to off-load the forums to my actual FogBugz On Demand account. However, I discover that FOD have no facility to integrate Single sing-on. I use django and have the option to use open-id, but not know if exist a way to make this happend. Obviously, I could hack a simple forums like the one on...

URLs stored in database for Django site

Hi guys, I've produced a few Django sites but up until now I have been mapping individual views and URLs in urls.py. Now I've tried to create a small custom CMS but I'm having trouble with the URLs. I have a database table (SQLite3) which contains code for the pages like a column for header, one for right menu, one for content.... so o...

What is an "app" in Django?

According to the documentation: An app is a Web application that does something -- e.g., a weblog system, a database of public records or a simple poll app. A project is a collection of configuration and apps for a particular Web site. A project can contain multiple apps. An app can be in multiple projects. However, w...

Content-Type and Representations

What is the common convention for supporting multiple representation (e.g. html, json, xml) for resources (e.g. blog, user) in django? First, I don't know how I should format my urls. For example, what your take on using either of these urls to request xml format /<resource>.<format>, e.g. /blogs/123.xml /<format>/<resource>, e.g. /x...

Deploying a Django website without access to httpd.conf (with or without mod_wsgi)

Can I deploy a django app with only write permissions in a particular folder on the server? For a recent work, I asked the admin to modify the .conf for me (and install mod_wsgi which was not present), but it would have been much less painful if I could have deployed the app by just uploading the files. (on apache) I don't have much e...

Updating Models

Due to my little confidence with Django and my sheer horror at the thought of seriously messing up my beautiful project, I shall ask for proper advice/instructions here. The database that my Django project is sitting on top of has been changed (a few field types have been changed) and my models are now out-of-sync. Funnily enough, my Dj...

The default "delete selected" admin action in Django

How can I remove or change the verbose name of the default admin action "delete selected X item" in the Django admin panel? ...

How to create annotation on filtered data in Django ORM?

I have the following models: class ApiUser(models.Model): apikey = models.CharField(max_length=32, unique=True) class ExtMethodCall(models.Model): apiuser = models.ForeignKey(ApiUser) method = models.CharField(max_length=100) #method name units = models.PositiveIntegerField() #how many units method call cost ...

Django: How do I make fields non-editable by default in an inline model formset?

I have an inline model formset, and I'd like to make fields non-editable if those fields already have values when the page is loaded. If the user clicks an "Edit" button on that row, it would become editable and (using JavaScript) I would replace the original widgets with editable ones. I'd like to do something like this when loading t...

How to create a custom 404 page for my Django/Apache?

I know that you use .htaccess in the document-root directory in standard apache. What if I use Django? Can someone give me step by step how to create a custom 404 page? THanks. ...

Create & return a default ImageFieldFile from inside a function

In my UserProfile model I would like to have a function which returns either the user's ImageFileField object or a default image if the user has not uploaded their own. For example: class UserProfile(models.Model): pic = models.ImageField('Headshot',blank=True, upload_to=get_path_and_filename) def...

Relative imports from __init__ in multi-file Django apps

I have a Django project located at /var/django/project/ where /var/django/ is in the PATH within that project I have: ___init__.py manage.py utils/ __init__.py tools.py utils/__init__.py contains a function named get_preview utils/tools.py contains a function named get_related How can utils/__init__.py import get_related fr...

Django - how can I get permalink to work with "throwaway" slug

I'm trying to add slugs to the url in my django app, much like SO does. Currently, I have pages that work just fine with a url like this: http://example.com/foo/123/ I'd like to add 'slugified' urls like so: http://example.com/foo/123/foo-name-here I can get it to work just fine, by simply modifying the urlconf and adding a throwa...