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(
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
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.
>
>
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.
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
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
> 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
> 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
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.
>
>
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
10 matches
Mail list logo