django

Ordering on a field in the 'through' Model of recursive ManyToMany relation in Django.

Assuming the following model: class Category(models.Model): related = models.ManyToManyField('self', symmetrical = False, through = 'CategoryRelation', null = True, blank = True) Assuming the following intermediate 'through' relation: class CategoryRelation(models.Model): source = models.ForeignKey('Category', null = False, b...

scripting ipython through django's shell_plus

I'm writing a shell script which runs a command through ipython with the -c option like this: ipython -c "from blah import myfunct; myfunct()" but I want to invoke ipython through django's shell_plus command so I can take advantage of all the stuff shell_plus automatically loads for me: $ ./manage.py shell_plus I can't just add "-c...

Is it possible to subclass a django model used in a many2many though relation?

Hi there, I was wondering whether it was possible to subclass a model used as the intermediate model in a M2M relation - and then display it through the usual ModelInline procedure... The code will explain it better (in models.py): from django.db import models from django.contrib import admin #the many2many_through model first class...

Django ORM in a python threaded application .. Does not exit

I have a standalone threaded python application in which I use Django's ORM (Postgres). After I join all my threads and wait for the application to exit(sys.exit(0)), there is still an extra thread running, for which the sys.exit waits: All the threads I started exited. Does Django spawn threads to handle database connectivity? This ...

Does __str__() call decode() method behind scenes?

It seems to me that built-in functions __repr__ and __str__ have an important difference in their base definition. >>> t2 = u'\u0131\u015f\u0131k' >>> print t2 ışık >>> t2 Out[0]: u'\u0131\u015f\u0131k' t2.decode raises an error since t2 is a unicode string. >>> enc = 'utf-8' >>> t2.decode(enc) ---------------------------------------...

Django Formset without instance

Hi. In this Django Doc explain how to create a formset that allows you to edit books belonging to a particular author. What I want to do is: Create a formset that allows you to ADD new book belonging to a NEW author... Add the Book and their Authors in the same formset. Can you gime a light? thanks. ...

How to prevent Satchmo forms from displaying asterisk after required fields?

I'm customizing my Satchmo store forms and have an icon that appears before any required fields. The problem is, Satchmo seems to want to render a text asterisk after the required fields. I'm using field.label to get this label, should I be using something else? EDIT: All my form templates are hard coded. I have an inclusion tag that...

Django Newsletter App

Is there any newsletter app for django, allowing users to subscribe-unsubscribe for newsletters? I'd like to have an app that's easy to use and administered via the Django admin. ...

Reusing django templates?

I find django's template language very limiting. Following along with django's DRY principle, I have a template that I'd like to use in many other templates. For example a patient list: {% for physician in physicians.all %} {% if physician.service_patients.count %} <div id="tabs-{{ forloop.counter }}"> {% include "hospitalists...

Django ModelForm CheckBox Widget

I'm currently have an issue, and likely overlooking something very trivial. I have a field in my model that should allow for multiple choices via a checkbox form (it doesn't have to be a checkbox in the admin screen, just in the form area that the end-user will see). Currently I have the field setup like so: # Type of Media MEDIA_CHOICE...

Django, Tiny_MCE break my css style in admin flatpage and dont appear

Hi guys, im trying to use the Tiny MCE editor in my FlatPages, but the Editor dont appear and the css of the add form in flatpage is broken. im using in this way: url.py (r'^tiny_mce/(?P<path>.*)$','django.views.static.serve',{'document_root': 'e:/wamp/www/diligencia/src/tiny_mce/jscripts/tiny_mce/'}), template: template overriding...

Migrating django.dispatch.dispatcher from Django 0.96 to 1.0.2

How does one perform the following (Django 0.96) dispatcher hooks in Django 1.0? import django.dispatch.dispatcher def log_exception(*args, **kwds): logging.exception('Exception in request:') # Log errors. django.dispatch.dispatcher.connect( log_exception, django.core.signals.got_request_exception) # Unregister the rollback event...

Really long query

How do u do long query? Is there way to optimize it? I would do complicated and long query: all_accepted_parts = acceptedFragment.objects.filter(fragmentID = fragment.objects.filter(categories = fragmentCategory.objects.filter(id=1))) but it doesn't work, i get: Error binding parameter 0 - probably unsupported type. I will be than...

InlineFormSet with queryset of different model

What we're trying to do is populate a list of inline forms with initial values using some queryset of a different model. We have products, metrics (some category or type or rating), and a rating, which stores the actual rating and ties metrics to products. class Product(models.Model): name = models.CharField(max_length=100) pric...

Django-Template : Get Variables in a Tag block !

Hello, I need to retrieve an optional number saved in DB , to a custom template tag i made . which to retrieve , a variable ( a photo ID ) included in this Gallery . within the gallery loop . {% get_latest_photo {{photo.id}} %} How to accomplish that ?! P.s : I know that can be done with inclusion tag , but in the present time h...

Django, how pass variable to flatpage???

Hi guys, im asking again :), i like that!!! jeej, im learning Django :D Well, i have a few flatpages in my app menu, so, my question is, how ill pass variables to my flatpages if i dont have any view for flatpages? here my url.py (r'',include('django.contrib.flatpages.urls')), i dont have any view's for any flatpages, so i dont know...

Simple JOIN in Django

I'm trying to accomplish something akin to twitter on my website, where one user can follow another one. I want to select all User records that are following a User with a given ID. My follow relationship model look like: class Following(models.Model): user = models.ForeignKey(User, related_name='is_following') followed = models.For...

permission_required decorator not working for me

I can't figure out why the permission required decorator isn't working. I would like to allow access to a view only for staff members. I have tried @permission_required('request.user.is_staff',login_url="../admin") def series_info(request): ... and also @permission_required('user.is_staff',login_url="../admin") def series_info(req...

Passing kwargs from template to view?

As you may be able to tell from my questions, I'm new to both python and django. I would like to allow dynamic filter specifications of query sets from my templates using **kwargs. I'm thinking like a select box of a bunch of kwargs. For example: <select id="filter"> <option value="physician__isnull=True">Unassigned patients</opti...

Get information from related object in generic list view

So, I've been noodling about with Django's generic views, specifically the object_list view. I have this in my urls.py: from django.conf.urls.defaults import * from django.views.generic import list_detail from diplomacy.engine.models import Game game_info = { "queryset": Game.objects.filter(state__in=('A', 'P')), "template_obj...