django

My Django manytomany fields are all marked unique, is there an option to remove this?

Given a model like this: class A(models.Model): def __unicode__(self): return "%d"%self.id class B(models.Model): a_set = models.ManyToManyField(A) def __unicode__(self): return "%d"%self.id Then the following series of operations demonstrates my problem: In [1]: a1=A() In [2]: a1.save() In [3]: a1 Out[3...

How to sort order in Django Related Models (Generic relations)

My models: HitCounter: hits = models.PositiveIntegerField(default=0) object_pk = models.TextField('object ID') content_type = models.ForeignKey(ContentType, verbose_name="content cype", related_name="content_type_set_for_%(class)s",) content_object = generic.GenericForeignKey('conte...

Have to Restart Apache When Using Django On Apache with mod_wsgi

I'm creating a web app with Django. Since I'm very familiar with Apache I setup my development environment to have Django run through Apache using mod_wsgi. The only annoyance I have with this is that I have to restart Apache everytime I change my code. Is there a way around this? ...

Django sending e-mail u'' around headers

Hello, I wrote a simple contact form for a client in Django. However, whenever it sends e-mail, it wraps the header values in u'' objects. For example, the From: header is From: (u'[email protected]',) Here's the code that sends the message: The form: class ContactForm(forms.Form): name = forms.CharField(max_length=100) sender = for...

Sorting based on the count in a related field in Django

I have two models, Image and Tag. Each Image object can have more than one Tag associated with it, and I want to find my most frequently used tags. How would I go about this? It seems easy enough but I can't seem to figure it out. ...

No module named urls

I'm following the Django Tutorials, I'm at the end of part 3, at Decoupling the URLconfs, at http://docs.djangoproject.com/en/1.1/intro/tutorial03/#intro-tutorial03 and I'm getting a "No module named urls" error message. When I change: from django.conf.urls.defaults import * from django.contrib import admin admin.autodiscover() urlpa...

How would you make a dynamic formset in Django?

Here's the way I'm doing it: {{ formset.management_form }} <table> {% for form in formset.forms %} {{ form }} {% endfor %} </table> <a href="javascript:void(0)" id="add_form">Add Form</a> And here's the JS: var form_count = {{formset.total_form_count}}; $('#add_form').click(function() { form_count++; var fo...

Clearing Django form fields on form validation error?

I have a Django form that allows a user to change their password. I find it confusing on form error for the fields to have the *'ed out data still in them. I've tried several methods for removing form.data, but I keep getting a This QueryDict instance is immutable exception message. Is there a proper way to clear individual form fields...

Must See Conference Videos for Python/Django Developers

There's lots of good conference videos online regarding Python and Django development. Instead of watching ST:TNG at the computer, I figure it'd more productive to hone my knowledge . Fire away with some of your most inspiring and educational Python, Django, or simply programming related talks. Provide an explanation of why you found th...

Django queries: how to filter objects to exclude id which is in a list?

How can I filter in a query so the result excludes any object instances with ID belonging to a list? Lets say I have: object_id_list = [1, 5, 345] MyObject.objects.filter(Q(time__gte=datetime.now()) & Q( ... what to put here? ... )) Something in the style of "SELECT * FROM ... WHERE id NOT IN (...)" ...

the django slug can't contain a "love" speech?

I use django-1.1 and satchmo (commit: 1385 75a2ea838067) I found that if there is a "love" speech in the slug item, for example, love-x10, dsfdsfloveddd, love-love ... the product's url is "http://example.com/product/lovelove/", if you click "add to cart" button, the server give me a Blank Page, Empty! And the server is temporarily una...

Django edit and delete from front end

Views.py def delete(request): customer = Customer.objects.get(id=5) customer.delete() return HttpResponse('deleted') Template.py <form method="POST" action="/customer/"> <div style="float: right; margin: 0px; padding: 05px; "> <p> Name : <select name ="delete_user"> {% for customer in customer %} ...

Limit Django's inlineformset_factory to only create new objects

I am using django's inline formset factory. To use the example in the docs, author = Author.objects.get(pk=1) BookFormSet = inlineformset_factory(Author, Book) formset = LicenceFormSet(request.POST, instance=author) will create an inline formset to edit books by a particular author. I want to create a formset that only allows users ...

Django problem with extends template tag

Hi, I'm trying to put variable from context processor into tag template 'extends': {% extends {{ base_template|default:"mainpage.html" }} %} but I got an exception: Exception Value: 'extends' takes one argument my context_processors.py: from django.conf import settings def search(request): """Adds settings for test""" return { ...

Django -- How to filter objects with an "author" from a set of "authors"(users)?

How to filter objects with an "author" from a set of "authors"(Users)? The "objects" are Posts, having an author(ForeignKey to User). I'm pretty much stumped by this, so I'd appreciate help with it. Of course one could go about this the naive way, by manually filtering them, but that would hit the database real hard. Thanks anyway. E...

Dynamically Delete inline formsets in Django

Is it possible to have Django automatically delete formsets that are not present in the request? So for example if I had three inline formsets represented in HTML when I loaded my edit page and I use javascript to remove two of those when the request is processes Django sees that those two forms are no longer their and deletes them. ...

Can a generic.GenericForeignKey() field be Null?

I am creating an object which tracks changes (Updates) regarding the creation, updating and deletion of other so called UUIDSyncable objects in the database. This involves any object which extends the UUIDSyncable classes's save() and delete() methods being overriden, in such a way that it creates a new Update object recording the actio...

View referenced by two urls and url tag

I am using url tag in my template for a view, that is used by two different urls. I am getting the wrong url in one place. Is there any way to force django to retrieve different url? Why it doesn't notify my, that such conflict occured and it doesn't know what to do (since python zen says, that is should refuse temptation to guess). Cod...

Why were the original authors of Django against include tags?

In this excellent Google Tech Talk by Jacob Kaplan-Moss, Jacob says that they added support for the include template tag despite previous dogmatic objections, and says that people shouldn't use it. Does anyone know why? A quick search didn't show anything that would explain why. There's nothing relevant in the now-fixed ticket where sup...

Explanation of contribute_to_class

I'm attempted to extend code, and have come across an issue, I don't understand a line of code. I know the outcome of it - but I don't understand how it happens and am naturally enough scared to change it. The line of code I've come across is this: MyGenericRelation().contribute_to_class(model, 'field_name') The result of this code i...