django

How to have a "random" order on a set of objects with paging in Django?

Hi, I have a model with 100 or so entries - the client would like these entries to appear in a 'random' order, but would also like paging in there. def my_view(request): object_list = Object.objects.all().order_by('?') paginator = Paginator(object_list, 10) page = 1 # or whatever page we have display_list = paginator.page(page)...

How to make Django admin site accessed by non-staff user?

Hello all, I would like to implement a 2nd admin site which provides a subset of feature of the primary admin site. That's possible and described in the Django docs However, I would like to limit access on the primary admin site. Some users can access the 2ndary site but not the primary site. In order to implement that feature, I woul...

django import a view function

I have a django application xxx which does a number of things. I also have a sepaerate application yyy. Which wants to call one of the functions of xxx. Is there a way for me to import the functions? For example, in yyy can i say from toplevel.xxx import doit Or what is the best approach, I dont want to duplicate code. ...

A Django seach form that I cannot make it work

Hello I have been recently working on Django search forms recently and have tired to edit one myself. Here is a search form that is supposed to find Clients. However When I type in a clients name, it does not display that client's name. So I am wondering What I am doing wrong. #model.py class Client(models.Model): comp...

Omitting fields on model "save" in django

I have a model, which has several "automatic" fields, like this: class Message(Model): subject = CharField(max_length = 200) message = TextField() created = DateTimeField() last_status_change = DateTimeField() status = CharField(max_length = 10) In my database (Postgres) I set up default values for created, last_st...

Django SSL error

I seem to get this error, and don't know how to debug it. Any pointers? Traceback (most recent call last): File "/opt/python2.6/lib/python2.6/site-packages/django/core/handlers/base.py", line 92, in get_response response = callback(request, *callback_args, **callback_kwargs) File "/www/django_test1/omu2/views.py", line 26, in...

quick question: how to associate a file with an ImageField in django?

Hello, i have an image saved on my HDD and i want to assign it to an ImageField, but i don't know how. i've tried something like this: object.imagefield.save(path,File(open(path))) But this makes an additional (invalid) copy of the image. Can someone help me please? thanks! ...

Problems rendering a view with tidy (Django + Apache mod_wsgi)

When running under the in-built development server, all runs fine. However, when running under mod_wsgi in Apache, the following code (a replacement method for django.shortcuts.render_to_response) causes an internal server error: # Tidy and render def render_tidy_response(*args, **kwargs): httpresponse_kwargs = { ...

Why is self.instance not set in clean function for a bound form?

I have a Django 1.1 model with unique_together on the owner and title where owner is foreign key on a user. This constraint is enforced but only after the clean. According to Django docs, I should be able to access self.instance to see non-form field object properties of a model instance. However, I get the error 'JournalForm' obje...

Django: saving a ModelForm with custom many-to-many models.

I have Publications and Authors. Since the ordering of Authors matters (the professor doesn't want to be listed after the intern that contributed some trivial data), I defined a custom many-to-many model: class Authorship(models.Model): author = models.ForeignKey("Author") publication = models.ForeignKey("Publication") order...

django and nginx - urls are all the same

Right now, any url just brings up a project default page ("welcome to django"). No matter what I put (example.com, example.com/hello, example.com/asdfjkasdf(&$(#$$#) I'm new to django and am following a simple tutorial. My nginx.conf has this: location / { # host and port to fastcgi server ...

Changing base template based on request.user in Django

I want to modify part of my base navigation menu based on a flag on the user model, without having to include request.user in every single view function in my codebase. The nav menu is part of the base template which every other template extends. Is there a simple way to do this (if so, I suck at search)? If not, is there a standard w...

Unknown column in mySQL CSV import

Hey everyone. I am trying to import a small CSV file into my django program. I am using SQL, and here is what I have so far. The CSV file itself has Column1 which is named Customer and I am trying to take that information and assign it to the model field name 'client_name'. Problem I get when I run this query is that I keep getting t...

Loading New Content with Ajax

This is a situation I've run into several times, not sure what the best approach is. Let's say I have some kind of dynamic content that users can add to via Ajax. For example, take Stack Overflow's comments - people can add comments directly on to the page using Ajax. The question is, how do I implement the addition itself of the new c...

Describe your customized Vim editor for Python/Django development?

I've recently switched entirely to Vim for all my Python/Django development. It took me a lot of time to customize it to the point it is today, and God knows how hard it was for me to find help regarding the best vim plugins out there suited for Python/Django development. I decided to ask this question so people like me could benefit di...

AppEngine + django: is reliable to rely on both?

I need to create a In-App-Purchase backend for a iPhone App, and think in build it on GAE. However, after my experience in a recent gig in one of the largest GAE customers and reading stuff like this http://www.agmweb.ca/blog/andy/2286/, I wonder if right now is good idea (ie: reliable) to host a django+gae project like this. I expect l...

django urlencode multiple variables in template

I want to url encode the following inside template {{address.street}} {{address.city}} {address.state}} is there anyway to do this on the template side and place it into an href( i prefer NOT to combine them on the server side): <a href="http://maps.google.com/maps?daddr=&lt;!-- OVER HERE --!>">Map It</a> thanks! ...

error: [Errno 32] Broken pipe when paypal calls back to python django app

Hi I am doing papal integration with my django app. i am using latest version of django from svn and python 2.6. However, i found every time when paypal's sandbox accessing my notify url i got 500 [Errno 32] Broken pipe my django stack. Does anyone have similar experience with this ? Cheers, Traceback (most recent call last): File...

How to keep a url param across pages

I wan't developers who embed my webapp to be able to pass a param in the url like ?style=dark which will alter the css accordingly. Is there a better way to keep this setting as the user navigates than appending ?style=dark to all links? I've considered cookies etc. but if one user is viewing two pages which embed my app with different ...

Django Poll for new records

In ajax I am polling a django url to retrieve the latest records. I do not want to display any records I have retrieved previously and I only want to retrieve 1 record for each poll request. What would be the best way to do this? ...