django

Alternative to using message_set (esp. for AnonymousUser)

In my Django site, I am planning on using message_set combined with some fancy UI to warn the user of things like "your operation was completed successfully" or "you have three new messages". The problem arises when I try to warn an user that is trying to log in that the user/pass he provided are wrong - AnonymousUser, for obvious reason...

Django: add image in an ImageField from image url

Hi, please excuse me for my ugly english ;-) Imagine this very simple model : class Photo(models.Model): image = models.ImageField('Label', upload_to='path/') I would like to create a Photo from an image URL (i.e., not by hand in the django admin site). I think that I need to do something like this : from myapp.models import Ph...

Django: problem with Javascipt. Getting 302 and 404 error

I am trying to run WMDEditor in my Django site. I have installed WMD files in a directory called /static/js/wmd.wmd.js of the root of my website. However when the page get served I get: INFO 2009-09-08 11:00:48,217 dev_appserver.py:3034] "GET /static/js/wmd/wmd. js HTTP/1.1" 302 - INFO 2009-09-08 11:00:48,733 dev_appserver.py:3...

Django Jquery sortable - how to access POST data

Nearly have this working but... the javascript calls django like this: .sortable({ connectWith: '.object', update: function() { var order = $(this).sortable('serialize'); $.ajax({ type: "POST", data: order, url: "/fo...

Django model inheritance, filtering models

Given the following models:(don't mind the TextFields there're just for illustration) class Base(models.Model): field1 = models.TextField() class Meta: abstract=True class Child1(Base): child1_field = models.TextField() class Child2(Base): child2_field = models.TextField() class Content(models.Model): aso_item...

keep settings in database

In a reusable application (in which i don't want to change any code) i would like to change a SETTING var that the application uses (in its forms and maybe other parts) to be dynamic (update its contents from a db table). What would be the best approach to do that (a middleware maybe?) ? ...

Proper way to handle multiple forms on one page in Django

I have a template page expecting two forms. If I just use one form, things are fine as in this typical example: if request.method == 'POST': form = AuthorForm(request.POST,) if form.is_valid(): form.save() # do something. else: form = AuthorForm() If I want to work with multiple forms however, how do I let...

Unexpected results feeding Django File upload object to Python CSV module

I have no problems getting the file to upload and if I save it to disk, all formatting is intact. I wrote a function to read in the the file within Django using: data = csv.reader(f.read()) where f is the Django file object that I get from 'form.cleaned_data['file']' and yes the file is already bound to the form. When I try to read ...

How to sort by annotated Count() in a related model in Django

Hi, I'm building a food logging database in Django and I've got a query related problem. I've set up my models to include (among other things) a Food model connected to the User model through an M2M-field "consumer" via the Consumption model. The Food model describes food dishes and the Consumption model describes a user's consumption o...

How Do I Select all Objects via a Relationship Model

Given the Model: class Profile(models.Model): user = models.ForeignKey(User, unique=True) class Thingie(models.Model): children = models.ManyToManyField('self', blank=True, symmetrical=False) class Relation(models.Model): profile = models.ForeignKey(Profile) thingie = models.ForeignKey(Thingie) How would one return ...

django newb, not seeing postback

I'm vaguely doing the django tutorial. <form action="." method="POST"> <input type="text" name="language" value="{{ fbuser.language|escape }}" /> <input type="submit" value="Change" /> </form> def canvas(request): if request.POST != {}: assert False, request.POST The assert never fires, and my request.POST is always {} and th...

Django how to save a custom formset

I've written the following custom formset, but for the life of me I don't know how to save the form. I've searched the Django docs and done extensive searches, but no one solution works. Lots of rabbit holes, but no meat ;-) Can someone point me in the right direction? // views.py partial // @login_required def add_stats(request, grou...

Polymorphism in Django

I have the following models. How do I get access to the unicode of the inheriting tables (Team and Athete) from the Entity table? I'm trying to display a list of all the Entities that displays 'name' if Team and 'firstname' and 'lastname' if Athlete. class Entity(models.Model): entity_type_list = (('T', 'Team'), ('A', 'Athlete')) ty...

Google Apps stops sending email every few days

Every few days, google apps starts rejecting my username and password with : SMTPAuthenticationError: (535, '5.7.1 Username and Password not accepted. Learn more at\n5.7.1 http://mail.google.com/support/bin/answer.py?answer=14257 22sm439603yxe.15') If I go to the google apps login page and try my password, it asks for a captcha. Filli...

Getting the history of an object

Hello I use django admin for my users to add their Model objects, as you know django is keeping the track of user actions such as the user who added an item. For an object, At a custom view outside the admin panel, I need to display the user name of the adder. How can I fetch/retrieve this data ? Cheers ...

Django: show list of many to many items in the admin interface

Hi, This might be a simple question, but i can't seem to grasp it. I have two simple models in models.py: Service and Host. Host.services has a m2m relationship with Service. In other words, a host has several services and one service can reside on multiple hosts; a basic m2m. models.py class Service(models.Model): servicena...

Problems with Snow Leopard, Django & PIL

Hi I am having some trouble getting Django & PIL work properly since upgrading to Snow Leopard. I have installed freetype, libjpeg and then PIL, which tells me: --- TKINTER support ok --- JPEG support ok --- ZLIB (PNG/ZIP) support ok --- FREETYPE2 support ok but when I try to upload a jpeg through the django admin interface I get: ...

Django Models absolute url - what am i doing wrong

Hello I am trying to set up links to a view that allows to edit objects, in previous view. Model: class List(models.Model): user = models.ForeignKey(User) name = models.CharField(max_length=200) type = models.PositiveIntegerField(choices=TYPE_DICT) def __unicode__(self): return self.name @models.permalink def get_absolute_url...

Django model inheritance - can I change model type?

When I use multi-table inheritance, Django creates two tables - one for the base class, and one for the derived one, pointing to the first. Is there a way to keep the base table entry while deleting the derived one, and create another entry for another model? To put it simpler: I have models: A, B(derived from A), C(derived from A). I w...

Django : import problem with python-twitter module

Hi, When I try to import python-twitter module in my app, django tries to import django.templatetags.twitter instead of python-twitter module (in /usr/lib/python2.5/site-packages/twitter.py), but I don't know why. :s For example: myproject/ myapp/ templatetags/ file.py In file.py: import twitter # this impor...