django

How do I send/get a JSON Object with Django?

I know how to use the JQuery ajax feature to call the "url view" of Django. import simplejson as json def the_view(request): fruits = {'color':5, 'type': 22} jfruit = json.dump(fruits) return render_to_response( THE JSON OBJECT!!! ...how? ) ...

Django - update a model won't delete the old FileField

Hello! I am implementing an application with django, which has a model with a FileField: class Slideshow(models.Model): name = models.CharField(max_length=30,unique=True) thumbnail = models.FileField(max_length=1000,upload_to="images/app/slideshows/thumbnails") and I have an admin backend where django manages the models. I jus...

Django | sort dict in template

I want to print out a dictionary, sorted by the key. Sorting the keys is easy in the view, by just putting the keys in a list and then sorting the list. How can I loop through the keys in the template and then get the value from the dictionary. {% for company in companies %} {% for employee, dependents in company_dict.company.items ...

Accessing request object from form.save

I'm using the pyfacebook module for Django to implement facebook Connect for one of my sites, I'm not using a local User object because I only want to use Facebook for login. I understand that I can't access the request object from the save method on a Django form, so how would I access the facebook object that the provided middleware g...

Increase speed for MySQL table creation in Django?

Some of my unit tests take 10-15 seconds just for mysql to create the tables. This seems unnecessarily long. It has to create around 50 tables, but that's still only 3 tables per second. This is a big annoyance when running unit tests over-and-over. As a workaround, I have been running my unit tests in sqlite3. It is blazing fast, but ...

Django: get parent objects matching condition on child

Couldn't think of a more appropriate question title, but I'm looking for some advice on how to implement the following requirement: I have a Project class, which may contain Task objects. Tasks have an assignee. In my Django template, I'd like to render a 'tree' of projects and tasks for a given user, showing only those projects that ha...

Uncommon django urlpattern

Hi folks. Suppose I've got urls on my site which look like /qwe/asd/zxc/wer/sdf/xcv/ (unknown number of \w+ blocks separated by slashes). Is that possible? to construct a urlpattern to catch those urls so that: a view function would get all those \w+ strings in *args list to it the {% url qwe asd zxc wer sdf xcv %} templatetag would r...

How to add 'collapse' to a Django StackedInline

In the same way you can add 'classes': ['collapse'] to one of your ModelAdmin fieldsets, I'd like to be able to have an Inline Model Admin be collapsible. This ticket, Collapse in admin interface for inline related objects, discusses exactly what I want to accomplish. But in the mean time, what's the best work around while we wait for ...

django template

I am overwriting an inline template - in my template I used: {% for line in fieldset %} {% for field in line %} <td class="original {{ field.field.name }}"> <div name="foobar_a"> {% ifequal field.field.name "rule_type" %} {% ifequal field.field "2" %} fine {% endifequal %} {% endifequal %} ...

Python: Get importing module's details from within imported module

I'm writing a piece of reusable code to import where I need it, but it needs some info about what is importing it. I have a workaround that does what I want, but it's a bit ugly. Is there a better way? Here is a simplified version of what I'm doing. What I want: Import a method and use it, but look at f in mod2. It needs some info from...

Using Python simplejson to return pregenerated json

I have a GeoDjango model object that I want't to serialize to json. I do this in my view: lat = float(request.GET.get('lat')) lng = float(request.GET.get('lng')) a = Authority.objects.get(area__contains=Point(lng, lat)) if a: return HttpResponse(simplejson.dumps({'name': a.name, 'area': a.a...

CMS subsites with Django

I'm using Django to create a site that provides a separate web UI for sorts of producers and consumers. Both UIs (or "subsites") have different layouts, menus and graphics. However they access the same database and models, just from different aspects (producer vs. consumer...).It's all hosted under a single domain, the UI differentiation...

Live editing in Django

Imagine you have an address book card. Normally the fields are displayed as static text, in a specific layout (imagine having multiple phone numbers, emails etc.). When editing it, you want to use the same layout, but with form fields instead of static text. It seems that the normal way of doing this in Django is to use separate views an...

Django: assign accesskey to label instead of select

Hi, i'm developing a site that must be as accessible as possible. While assigning the accesskeys to my form fields with widget=FieldWidget(attrs={'accesskey':'A'}) i found out that the w3c validator won't validate an xhtml strict page with an accesskey in a select tag. Anyway i couldn't find a way to assign an accesskey to the label rel...

Complex Django query over foreign keys

I have two models in the same application. The application is called "News", and it has two classes in its model called "Article" and "Category". class Category(models.Model): name = models.CharField(_("Name"), max_length=100) slug = models.SlugField(_("Slug"), max_length=100, unique=True) class Article(models.Model): categ...

Django - Allow duplicate usernames

I'm working on a project in django which calls for having separate groups of users in their own username namespace. So for example, I might have multiple "organizations", and username should only have to be unique within that organization. I know I can do this by using another model that contains a username/organization id, but that ...

Django DateField default options

I have a model which has a date time field: date = models.DateField(_("Date"), default=datetime.now()) When I check the app in the built in django admin, the DateField also has the time appended to it, so that if you try to save it it returns an error. How do I make the default just the date? (datetime.today() isn't working either) ...

Django + Google App Engine: app engine helper for django or use_library?

There seem to be 2 ways to use django 1.1 with GAE Google App Engine helper for django The new use_library() function We currently use the first. Should we switch? And what's the difference between the two? ...

Jquery in Django: Which django apps should I look into?

I want to use some jquery in my forms and I was hoping to use some ready made solutions - there seem to be a lot of them... Which django apps would you recommend for this purpose? Which are most popular? EDIT #1: Hmmmm... I suppose I didn't put enough effort into my question... I was hoping for more options/clarifications... There se...

Keeping track of changes since the last save in django models

A couple of times I've run into a situation, when at save time I need to know which model fields are going to be updated and act accordingly. The most obvious solution to this is to take the primary key field and retrieve a copy of the model from the database: class MyModel(models.Model): def save(self, force_insert=False, force_u...