Re: get_absolute_url() using related models slugs

2008-04-25 Thread Merrick

Thank you Malcolm and Karen, I had to step for the day but when I got
home I read your comments and fixed the issue which was exactly as you
both pointed out.

this helped make my photo model much more search friendly.

@permalink
def get_absolute_url(self):
return ('photo_detail',  None, { 'state' :
self.place.city.state.slug , 'city' : self.place.city.slug, 'place' :
self.place.slug, 'slug': self.slug })

and in my views.py

#photo
url(r'^photo/(?P[-\w]+)/(?P[-\w]+)/(?P[-\w]+)/
(?P[\-\d\w]+)/$',
  view = 'photologue.views.photo_detail',
  name = 'photo_detail',
),


On Apr 24, 11:43 am, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Thu, Apr 24, 2008 at 12:21 PM, Merrick <[EMAIL PROTECTED]> wrote:
>
> > Thank you, I updated get_absolute_url to take into consideration the
> > fact that I was erroneously using state_slug instead of state.slug and
> > the same with photo.slug and place.slug
>
> >def get_absolute_url(self):
> >return ('photo-detail',  None, { 'state' :
> > self.photo.place.city.state.slug , 'city' :
> > self.photo.place.city.slug, 'place' : self.photo.place.slug, 'slug':
> > self.slug })
>
> > >>> from photologue.models import *
> > >>> photo = Photo.objects.get(slug='golf-course-3')
> > >>> photo.get_absolute_url()
>
> > still getting this error:
>
> > AttributeError: 'RelatedManager' object has no attribute 'place'
>
> As Malcolm said, within get_absolute_url, self is already the Photo
> instance, so it is confusing what you are trying to get at when you use
> 'self.photo' here.  In fact given the models you have defined, self.photo is
> referencing the model manager for the set of Gallery instances that have
> self as 'featured_photo'.  (I think you might want to rethink that
> related_name specification, since it seems to be confusing enough to have
> tripped you up here.)
>
> Within get_absolute_url, to refer to the photo instance, just use self, not
> self.photo.  When you fix that you are going to hit an error because the
> Place model does not have a slug field, and yet you are trying to access it
> when you code self.place.slug.  I don't know what you are really intending
> to specify here.
>
> Karen
>
>
>
> > On Apr 24, 8:59 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
> > wrote:
> > > On Thu, 2008-04-24 at 08:55 -0700, Merrick wrote:
>
> > > [...]
>
> > > > ***Shell output
>
> > > > >>> from photologue.models import *
> > > > >>> photo = Photo.objects.get(slug='golf-course-3')
> > > > >>> photo.place.city.state_slug
> > > > Traceback (most recent call last):
> > > >   File "", line 1, in ?
> > > > AttributeError: 'City' object has no attribute 'state_slug'
>
> > > This is telling you exactly what the error is. You're accessing a
> > > non-existent attribute on the City model. Maybe you mean to state.slug
> > > instead of state_slug or maybe you mean something else there. In any
> > > case, there is no state_slug attribute.
>
> > > Malcolm
>
> > > --
> > > He who laughs last thinks slowest.http://www.pointy-stick.com/blog/
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: get_absolute_url() using related models slugs

2008-04-24 Thread Karen Tracey
On Thu, Apr 24, 2008 at 12:21 PM, Merrick <[EMAIL PROTECTED]> wrote:

>
> Thank you, I updated get_absolute_url to take into consideration the
> fact that I was erroneously using state_slug instead of state.slug and
> the same with photo.slug and place.slug
>
>def get_absolute_url(self):
>return ('photo-detail',  None, { 'state' :
> self.photo.place.city.state.slug , 'city' :
> self.photo.place.city.slug, 'place' : self.photo.place.slug, 'slug':
> self.slug })
>
> >>> from photologue.models import *
> >>> photo = Photo.objects.get(slug='golf-course-3')
> >>> photo.get_absolute_url()
>
> still getting this error:
>
> AttributeError: 'RelatedManager' object has no attribute 'place'
>

As Malcolm said, within get_absolute_url, self is already the Photo
instance, so it is confusing what you are trying to get at when you use
'self.photo' here.  In fact given the models you have defined, self.photo is
referencing the model manager for the set of Gallery instances that have
self as 'featured_photo'.  (I think you might want to rethink that
related_name specification, since it seems to be confusing enough to have
tripped you up here.)

Within get_absolute_url, to refer to the photo instance, just use self, not
self.photo.  When you fix that you are going to hit an error because the
Place model does not have a slug field, and yet you are trying to access it
when you code self.place.slug.  I don't know what you are really intending
to specify here.

Karen


>
>
> On Apr 24, 8:59 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
> wrote:
> > On Thu, 2008-04-24 at 08:55 -0700, Merrick wrote:
> >
> > [...]
> >
> > > ***Shell output
> >
> > > >>> from photologue.models import *
> > > >>> photo = Photo.objects.get(slug='golf-course-3')
> > > >>> photo.place.city.state_slug
> > > Traceback (most recent call last):
> > >   File "", line 1, in ?
> > > AttributeError: 'City' object has no attribute 'state_slug'
> >
> > This is telling you exactly what the error is. You're accessing a
> > non-existent attribute on the City model. Maybe you mean to state.slug
> > instead of state_slug or maybe you mean something else there. In any
> > case, there is no state_slug attribute.
> >
> > Malcolm
> >
> > --
> > He who laughs last thinks slowest.http://www.pointy-stick.com/blog/
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: get_absolute_url() using related models slugs

2008-04-24 Thread Merrick

Thank you, I updated get_absolute_url to take into consideration the
fact that I was erroneously using state_slug instead of state.slug and
the same with photo.slug and place.slug

def get_absolute_url(self):
return ('photo-detail',  None, { 'state' :
self.photo.place.city.state.slug , 'city' :
self.photo.place.city.slug, 'place' : self.photo.place.slug, 'slug':
self.slug })

>>> from photologue.models import *
>>> photo = Photo.objects.get(slug='golf-course-3')
>>> photo.get_absolute_url()

still getting this error:

AttributeError: 'RelatedManager' object has no attribute 'place'


On Apr 24, 8:59 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Thu, 2008-04-24 at 08:55 -0700, Merrick wrote:
>
> [...]
>
> > ***Shell output
>
> > >>> from photologue.models import *
> > >>> photo = Photo.objects.get(slug='golf-course-3')
> > >>> photo.place.city.state_slug
> > Traceback (most recent call last):
> >   File "", line 1, in ?
> > AttributeError: 'City' object has no attribute 'state_slug'
>
> This is telling you exactly what the error is. You're accessing a
> non-existent attribute on the City model. Maybe you mean to state.slug
> instead of state_slug or maybe you mean something else there. In any
> case, there is no state_slug attribute.
>
> Malcolm
>
> --
> He who laughs last thinks slowest.http://www.pointy-stick.com/blog/
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: get_absolute_url() using related models slugs

2008-04-24 Thread Malcolm Tredinnick


On Thu, 2008-04-24 at 09:08 -0700, Merrick wrote:
> Sorry to confuse things, I actually thought putting the shell output
> would give a bigger picture.
> 
> The problem I am trying to solve is getting related to
> get_absolute_url()
> 
> >>> photo.get_absolute_url()
> Traceback (most recent call last):
>   File "", line 1, in ?
>   File "/usr/lib/python2.4/site-packages/django/utils/functional.py",
> line 55, in _curried
> return _curried_func(*(args+moreargs), **dict(kwargs,
> **morekwargs))
>   File "/usr/lib/python2.4/site-packages/django/db/models/base.py",
> line 478, in get_absolute_url
> return settings.ABSOLUTE_URL_OVERRIDES.get('%s.%s' %
> (opts.app_label, opts.module_name), func)(self, *args, **kwargs)
>   File "/usr/lib/python2.4/site-packages/django/db/models/
> __init__.py", line 31, in inner
> bits = func(*args, **kwargs)
>   File "/var/virtualhosts/picturemexico/photologue/models.py", line
> 351, in get_absolute_url
> return ('photo-detail',  None, { 'state' :
> self.photo.place.city.state_slug , 'city' :
> self.photo.place.city_slug, 'place' : self.photo.place_slug, 'slug':
> self.slug })
> AttributeError: 'RelatedManager' object has no attribute 'place'

I have no idea what "self.photo" is referring to there, since "self" is
the Photo instance and it doesn't have a "photo" attribute. I'm pretty
tired at the moment, so maybe I'm missing something, or maybe you didn't
post your actual code. In any case, it looks like the "self.photo" bit
is just wrong, so I'd start by fixing that.

Malcolm

-- 
Why can't you be a non-conformist like everyone else? 
http://www.pointy-stick.com/blog/


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: get_absolute_url() using related models slugs

2008-04-24 Thread Merrick

Sorry to confuse things, I actually thought putting the shell output
would give a bigger picture.

The problem I am trying to solve is getting related to
get_absolute_url()

>>> photo.get_absolute_url()
Traceback (most recent call last):
  File "", line 1, in ?
  File "/usr/lib/python2.4/site-packages/django/utils/functional.py",
line 55, in _curried
return _curried_func(*(args+moreargs), **dict(kwargs,
**morekwargs))
  File "/usr/lib/python2.4/site-packages/django/db/models/base.py",
line 478, in get_absolute_url
return settings.ABSOLUTE_URL_OVERRIDES.get('%s.%s' %
(opts.app_label, opts.module_name), func)(self, *args, **kwargs)
  File "/usr/lib/python2.4/site-packages/django/db/models/
__init__.py", line 31, in inner
bits = func(*args, **kwargs)
  File "/var/virtualhosts/picturemexico/photologue/models.py", line
351, in get_absolute_url
return ('photo-detail',  None, { 'state' :
self.photo.place.city.state_slug , 'city' :
self.photo.place.city_slug, 'place' : self.photo.place_slug, 'slug':
self.slug })
AttributeError: 'RelatedManager' object has no attribute 'place'


On Apr 24, 8:59 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Thu, 2008-04-24 at 08:55 -0700, Merrick wrote:
>
> [...]
>
> > ***Shell output
>
> > >>> from photologue.models import *
> > >>> photo = Photo.objects.get(slug='golf-course-3')
> > >>> photo.place.city.state_slug
> > Traceback (most recent call last):
> >   File "", line 1, in ?
> > AttributeError: 'City' object has no attribute 'state_slug'
>
> This is telling you exactly what the error is. You're accessing a
> non-existent attribute on the City model. Maybe you mean to state.slug
> instead of state_slug or maybe you mean something else there. In any
> case, there is no state_slug attribute.
>
> Malcolm
>
> --
> He who laughs last thinks slowest.http://www.pointy-stick.com/blog/
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: get_absolute_url() using related models slugs

2008-04-24 Thread Malcolm Tredinnick


On Thu, 2008-04-24 at 08:55 -0700, Merrick wrote:
[...]
> ***Shell output
> 
> >>> from photologue.models import *
> >>> photo = Photo.objects.get(slug='golf-course-3')
> >>> photo.place.city.state_slug
> Traceback (most recent call last):
>   File "", line 1, in ?
> AttributeError: 'City' object has no attribute 'state_slug'

This is telling you exactly what the error is. You're accessing a
non-existent attribute on the City model. Maybe you mean to state.slug
instead of state_slug or maybe you mean something else there. In any
case, there is no state_slug attribute.

Malcolm

-- 
He who laughs last thinks slowest. 
http://www.pointy-stick.com/blog/


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



get_absolute_url() using related models slugs

2008-04-24 Thread Merrick

I am still learning Django, and appreciate all of the help I have
received. I spent a few hours on this and just cannot figure out how
to pull off the get_absolute_url() function the way I describe it
below for the Photo class. I want to use the slugs for related models
and step through multiple relations. I can get to the id's of the
related models as shown in the shell transcript below, but not the
slugs yet.

extracted from models.py

class State(models.Model):
state = models.CharField(max_length=100, unique=True)
slug = models.SlugField(prepopulate_from=('state',))

class City(models.Model):
state = models.ForeignKey(State)
featured_place = models.ForeignKey('Place', related_name='place',
null=True, blank=True)
city = models.CharField(max_length=100, unique=True)
slug = models.SlugField(prepopulate_from=('city',))

class Place(models.Model):
city = models.ForeignKey(City)
featured_gallery = models.ForeignKey('Gallery',
related_name='gallery', null=True, blank=True)


class Gallery(models.Model):
user = models.ForeignKey(User)
place = models.ForeignKey(Place)
featured_photo = models.ForeignKey('Photo', related_name='photo',
null=True, blank=True)
pub_date = models.DateTimeField(_('date published'),
default=datetime.now)
title = models.CharField(_('title'), max_length=100, unique=True)
slug = models.SlugField(_('slug'), prepopulate_from=('title',),
unique=True,
help_text=_('A "Slug" is a unique URL-
friendly title for an object.'))
is_public = models.BooleanField(_('is public'), default=True,
help_text=_('Public galleries will
be displayed in the default views.'))
photos = models.ManyToManyField('Photo', related_name='galleries',
verbose_name=_('photos'), filter_interface=models.HORIZONTAL)

class Photo(models.Model):
user = models.ForeignKey(User)
place = models.ForeignKey(Place)
image = models.ImageField(_('photograph'), upload_to=PHOTOLOGUE_DIR
+"/photos/%Y/%b/%d")
pub_date = models.DateTimeField(_('date published'),
default=datetime.now)
title = models.CharField(_('title'), max_length=100, unique=True)
slug = models.SlugField(_('slug'), prepopulate_from=('title',),
unique=True,
help_text=('A "Slug" is a unique URL-
friendly title for an object.'))

@permalink
def get_absolute_url(self):
return ('photo-detail',  None, { 'state' :
self.photo.place.city.state_slug , 'city' :
self.photo.place.city_slug, 'place' : self.photo.place_slug, 'slug':
self.slug })

***Shell output

>>> from photologue.models import *
>>> photo = Photo.objects.get(slug='golf-course-3')
>>> photo.place.city.state_slug
Traceback (most recent call last):
  File "", line 1, in ?
AttributeError: 'City' object has no attribute 'state_slug'

>>> photo.place.city.state_id
4

>>> photo.get_absolute_url()
return ('photo-detail',  None, { 'state' :
self.photo.place.city.state_slug , 'city' :
self.photo.place.city_slug, 'place' : self.photo.place_slug, 'slug':
self.slug })
AttributeError: 'RelatedManager' object has no attribute 'place'


Any hints would be appreciated.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---