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...
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...
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?
...
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...
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.
...
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...
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...
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...
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...
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 (...)"
...
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...
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 %}
...
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 ...
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 {
...
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...
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.
...
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...
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...
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...
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...