django

Querying many to many fields in django

In the models there is a many to many fields as, from emp.models import Name def info(request): name = models.ManyToManyField(Name) And in emp.models the schema is as class Name(models.Model): name = models.CharField(max_length=512) def __unicode__(self): return self.name Now when i want to query a...

cannot append Model.objects.all()

I cannot run ['abc'].append( MyModel.objects.all() ) since it generates exception 'NoneType' object is not iterable if MyModel has no entry. any workaround or something like ? : in c++ edit: my statement is actually ','.join([ str(e) for e in ['abc','def'].append( MyModel.objects.all() ) ]) it seems that the problem is caused by ...

Added tagging to existing model, now how does its admin work?

I wanted to add a StackOverflow-style tag input to a blog model of mine. This is a model that has a lot of data already in it. class BlogPost(models.Model): # my blog fields try: tagging.register(BlogPost) except tagging.AlreadyRegistered: pass I thought that was all I needed so I went through my old database of blog post...

Run Django as Windows Service

I run Django on Windows Server 2k3 under Nginx using FastCGI. Nginx is is running as Windows service and is easy to manage and autostart. Nginx is running using WINSW tool. I want to make the same for Django app and need to find a way to do it. Django should be started as separate FCGI application using this command: python manage.py...

Matplotlib and WSGI/mod_python not working on Apache.

Everything works as supposed to on the Django development server. In Apache, the django app also works except when matplotlib is used. Here's the error I get: No module named multiarray. Exception Type: ImportError Exception Value: No module named multiarray Exception Location: /usr/share/pyshared/numpy/core/numerictypes.py in <modu...

What should I use - Mako or Django?

Hi guys, I'm making a website that mail users when a movie or a pc game has released. It isn't too complex - users can sign up, choose movies/music or a genre and save the settings. When the movie/music is released - it mails the user. Some other functionality too but this is the jist. Now, I've been working with Python for a bit but m...

Is django-notification meant for adding extra notification message transports?

Subj. In particular, I want to add XMPP notifications (over my own XMPP message sending facilities), with some possible non-simple features (like selecting a message source jid or considering user's current XMPP status). Or I should create a wrapper for notification's send() after all? ...

Google App Engine (python): TemplateSyntaxError: 'for' statements with five words should end in 'reversed'

This is using the web app framework, not Django. The following template code is giving me an TemplateSyntaxError: 'for' statements with five words should end in 'reversed' error when I try to render a dictionary. I don't understand what's causing this error. Could somebody shed some light on it for me? {% for code, name in charts.item...

Web-based game in Python + Django and client browser polling

I am creating a text-based game that implements a basic model in which multiple (10+) players interact with data and one moderator watches them and sets certain environmental statistics that affect gameplay. Recently I have begun to familiarize myself with Django. It seems to me that it would be an excellent tool for creating a game qu...

Django: one form for two models (solved)

UPDATE The issue is solved, all the code you can see works. Hello! I have a ForeignKey relationship between TextPage and Paragraph and my goal is to make front-end TextPage creating/editing form as if it was in ModelAdmin with 'inlines': several fields for the TextPage and then a couple of Paragraph instances stacked inline. The proble...

Dynamic variable name in python

I'd like to call a query with a field name filter that I wont know before run time... Not sure how to construct the variable name ...Or maybe I am tired. field_name = funct() locations = Locations.objects.filter(field_name__lte=arg1) where if funct() returns name would equal to locations = Locations.objects.filter(name__lte=arg1) N...

django how get session in models

django how get session in models or how get session out views ...

Django - Threading in views without hanging the server

One of my applications in my Django project require each request/visitor to that instance to have their own thread. This might sound confusing, so I'll describe what I'm looking to accomplish in a case based scenario, with steps: User visits application Thread starts Until the thread finishes, that user's server instance hangs Once the...

Django: Summing values of records grouped by foreign key

Hi there In django, given the following models (slightly simplified), I'm struggling to work out how I would get a view including sums of groups class Client(models.Model): api_key = models.CharField(unique=True, max_length=250, primary_key=True) name = models.CharField(unique=True, max_length=250) class Purch...

django search and filter in Google App Engine

Hi, I'm trying to add filter and search to my site. It's exactly the same code as in another working django project. The difference is that this time I do it with app engine. my views: http://slexy.org/view/s21GMw2sh1 I have 2 problems: 1.) I get error: "'Query' object has no attribute 'all'" on line 59 in views. As I understand it'...

Is there a Django template tag that lets me set a context variable?

I want to be able to set variables in a template to string values. I wrote a tag, but it doesn't seem to change the context. The intended use is: {% define "a string" as my_var %} Update (solved): class DefineNode(Node): def __init__(self, var, name): self.var = var self.name = name def __repr__(self): ...

Writing custom Django form fields and widgets

Django has very good documentation that describes how to write custom database fields and custom template tags and filters. I cannot find the document that describes how to write custom form fields and widgets. Does this document exist? The way I've been able to write custom form fields and widgets is by reading the Django source code...

django manual login and redirect

Hello I have such view that handles user registration. After creating new user i want to manually authenticate it and log it in.: def register(request): ... ... if form.is_valid(): username = form.cleaned_data['username'] password = form.cleaned_data['password1'] email = '' newuser = User.ob...

How to make a Django model fields calculated at runtime?

I have a model: class Person (models.Model): name = models.CharField () birthday = models.DateField () age = models.IntegerField () I want to make age field to behave like a property: def get_age (self): return (datetime.datetime.now() - self.birthday).days // 365 age = property (get_age) but a...

Run django tests from a browser

I'd like to provide a browser page to help non-techies run the various tests I've created using the standard django test framework. The ideal would be for a way to display all the tests found for an application with tick boxes against each one, so the user could choose to run all tests or just a selection. Output would be displayed in ...