Best Practices for filter()[0] and get()

2009-02-06 Thread Michael Burton
I often have a need to get an object that I don't know for sure is in the database. For example, Retrieving a person by username when the username may have been mistyped, eg. User.objects.get(...) Retrieving a user's most recently used location, if they have one, eg. Location.objects.filter(

Accessing SQL result by column name

2008-07-10 Thread Michael Burton
Hi everyone, I'd like to use column names rather than positions to access the results of my Django SQL queries. For example, > cursor = connection.cursor() > cursor.execute('select a, b, c from foo') > rows = cursor.fetchall() > print rows['a'] The above code gives me an error

Re: Having a Many-to-One relationship with multiple other models

2008-05-13 Thread Michael Burton
best that you are explicit > about the presence of the foreign keys and code ForeignKey(x, null=True) > within the Photo model.  But if you want the "directionality" to go the way > you indicate, I do think it is correct and more elegant to have the > intermediate join table. > >  

Re: Having a Many-to-One relationship with multiple other models

2008-05-13 Thread Michael Burton
anyField.  The join table would be structured > exactly the same, except it would have an additional UNIQUE(photo_id) > qualifier. > >   -- Scott > > > > On Tue, May 13, 2008 at 2:56 PM, Michael Burton <[EMAIL PROTECTED]> wrote: > > > Thanks much, Scott.

Re: Having a Many-to-One relationship with multiple other models

2008-05-13 Thread Michael Burton
eating a > join >    table connecting each pair of models. >    2. Create two ForeignKey fields in Photo, one to UserProfile and one >    to Photo, with null=True.  Yes, this is a bit ugly. :) > >   -- Scott > > > > On Tue, May 13, 2008 at 2:24 PM, Michael Burton <[EM

Having a Many-to-One relationship with multiple other models

2008-05-13 Thread Michael Burton
I have some Places and I have some Users in my database. I'd like to be able to associate some Photos with each. class Photo(models.Model): # a model that represents a photo class UserProfile(models.Model): # has a list of Photos class Place(models.Model): # has a list of Pho

Re: Django and Services

2008-05-02 Thread Michael Burton
> I'll have to disagree with you here.  I think this is a perfect > example of Russ's point.  Somewhere on your PYTHONPATH just write a > function that looks something like this (warning, untested code): > > from django.shortcuts import render_to_response as old_rtr > from django.template import R

Re: Django and Services

2008-05-01 Thread Michael Burton
> Ah.. the singleton... Java's answer to the fact that not everything is > an object. :-) Ha ha, fair enough Russ :) And I don't dispute a certain java- oriented predisposition to the way i think about these problems. But let me bring a point in favor of the Singleton, and why I think it might

Re: Django and Services

2008-05-01 Thread Michael Burton
Mike On May 1, 3:16 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > You actually would place the on the model, for example you might have > a send_email method on an invitation model, to abstract the template, > simply make it a parameter to the function. > >

Django and Services

2008-05-01 Thread Michael Burton
I'm coming to Django from the Java Spring MVC world, and over in those remote lands we have something called a "Service" layer. The service layer is responsible for doing all the business logic that your views might otherwise do. For example, you might have something like: class UserSer