django

django display content manytomanyfield

Hi all, I'm trying to show the content of a manytomanyfield in the admin interface. I have the following code: class Member(models.Model): group = models.ManyToManyField('Group') def group_gp_name(self): return self.group.gp_name def __unicode__(self): return u'%s' % (self.id) class Group(models.Model): ...

How to pass object_id to generic view object_detail in Django

I'm using django.views.generic.list_detail.object_detail. According to the documentation the view takes the variable object_id. To do this I added the following to my urlconf: (r'^(?P<object_id>\d+)$', list_detail.object_detail, article_info), The above line is in a separate urlconf that is included in the main urlconf. If I leave t...

Proper way to call a database function from Django?

Hi, i'm triyng to make a full text search with postgresql and django So I've created a function search_client(text) which returns a list of clients. To call it from the DB i use something like this: SELECT * FROM search_client('something') and i'm not really sure how to call it from django. i know i could do something like cursor = c...

Python/Django BooleanField model with RadioSelect form default to empty

Hello all, I'm using a Django ModelForm where my model contains a BooleanField and the form widget associated with that BooleanField is a RadioSelect widget. I'd like the the RadioSelect widget that renders to have no options selected so the user has to explicitly make a choice, but the form validation to fail if they make no selection...

virtualenv, sys.path and site-packages

i am setting up a virtualenv for django deployment. i want an isolated env without access to the global site-packages. i used the option --no-site-packages, then installed a local pip instance for that env. after using pip and a requirements.txt file i noticed that most packages were installed in a "build" folder that is not in sys.pa...

How do I access environ variables in Django's wsgi?

I am using this code to run django within twisted. from django.core.handlers.wsgi import WSGIHandler def wsgi_resource(): pool = threadpool.ThreadPool() pool.start() # Allow Ctrl-C to get you out cleanly: reactor.addSystemEventTrigger('after', 'shutdown', pool.stop) real_wsgi_app = WSGIHandler() def my_wsgi_wrap...

Reusing a Django RSS Feed for different Date Ranges

What would be a way to have date range based rss feeds in Django. For instance if I had the following type of django rss feed model. from django.contrib.syndication.feeds import Feed from myapp.models import * class PopularFeed(Feed): title = '%s : Latest SOLs' % settings.SITE_NAME link = '/' description = 'Latest entries t...

The listener does not work! Django-signals.

from django.db.models.signals import post_save class MyModel(models.Model): int = models.PositiveIntegerField(unique=True) def added (sender, instance, **kwargs): print 'Added' post_save.connect(added,MyModel) When I do: MyModel.objects.create(int=12345).save() nothing happened Am i lose something? After Edit: Not ...

Django URLField and HTML5?

Is it possible to make django's (v1.2) URLField output an HTML5 input tag where type="url"? ------------- SOLUTION ------------- from django.forms import ModelForm from django.forms import widgets from django.forms import fields from models import MyObj class URLInput(widgets.Input): input_type = 'url' class MyObjForm(ModelForm):...

Django - multiple databases and auth.Permission

I'm working on a project that needs two databases - one for the "logged out" portion and one for the logged in. I need the auth (and therefore contenttypes) app synched to both databases, which is working fine. However, the management commands for auth and contenttypes that create the default Permission and ContentType objects aren't run...

Django Admin - Overriding the widget of a custom form field

Hi All, I have a custom TagField form field. class TagField(forms.CharField): def __init__(self, *args, **kwargs): super(TagField, self).__init__(*args, **kwargs) self.widget = forms.TextInput(attrs={'class':'tag_field'}) As seen above, it uses a TextInput form field widget. But in admin I would like it to be disp...

"Cannot filter a query once a slice has been taken"

I get this error Caught AssertionError while rendering: Cannot filter a query once a slice has been taken. On this line {% if form.non_field_errors %} When I try to do this copy_pickup_address = ModelChoiceField(required=False, queryset=Address.objects.filter(shipment_pickup__user=user).order_by('-shipment_pickup__created')[:5...

In Django, how to limit entries from each user to a specific number N (N > 1)?

I have a Django web application that's similar to the typical Q&A system. A user asks a question. other users submit answers to that question: Each user is allowed to submit up to N answers to each question, where N > 1 (so, say each user can submit no more than 3 answers to each question) A user can edit his existing answers, or sub...

Send mail with python using bcc

I'm working with django, i need send a mail to many emails, i want to do this with a high level library like python-mailer, but i need use bcc field, any suggestions? ...

Django forms integerField set max_value on runtime

I've got a form like this: class SomeForm(forms.Form): first = forms.IntegerField(max_value= DontWantToSetYet) second = forms.IntegerField(max_value= DontWantToSetYet) third = forms.IntegerField(max_value= DontWantToSetYet) How can I set the max_values at runtime? I.E if request.method == 'POST': form = SomeForm(request.POST, ...

Get field class?

I've got a field defined like this country = ChoiceField(initial='CA', choices=COUNTRIES, widget=Select(attrs={'class':'address country'})) Notice how attrs is set. How can I retrieve this inside the template? I'm trying things like {{country.widget.attrs.class}} But nothing seems to be working. ...

[Django] What's the easiest/cleanest way to get the MessageID of a sent email?

I want to save the MessageID of a sent email, so I can later use it in a References: header to facilitate threading. I see in root/django/trunk/django/core/mail.py (line ~55) where the MessageID is created. I'm trying to think of the best way to collect this value, other than just copy/pasting into a new backend module and returning it...

django, show fields on admin site that are not in model

Hello, Building a Django app. Class Company(models.Model): trucks = models.IntegerField() multiplier = models.IntegerField() #capacity = models.IntegerField() The 'capacity' field is actually the sum of (trucks * multiplier). So I don't need a database field for it since I can calculate it. However, my admin user wants ...

Why is Django-lean test failing with "NoReverseMatch: Reverse for 'opensearch' with arguments '()' and keyword arguments '{}' not found."

I'm confused why my tests won't pass for the Django-lean module. ====================================================================== ERROR: testIntegrationWithRegisteredUser (django_lean.experiments.tests.test_tags.ExperimentTagsTest) ---------------------------------------------------------------------- Traceback (most recent call l...

Be my human compiler: What is wrong with this Python 2.5 code?

My framework is raising a syntax error when I try to execute this code: from django.template import Template, TemplateSyntaxError try: Template(value) except TemplateSyntaxError as error: raise forms.ValidationError(error) return value And here's the error: from template_field import TemplateTextFi...