understanding how product subtypes work

2 views
Skip to first unread message

Benjamin Edwards

unread,
May 4, 2009, 11:48:01 AM5/4/09
to Satchmo users
Hi all,

I am trying to implement a custom product module, and ideally I would
like to do it via model inheritance à la <a href="http://
thisismedium.com/labs/satchmo-diaries-part-one/">Bob Waycott</a>.
Unfortunately I have hit some snags. Before I go any further, here is
the model..

<pre>
class Ring(Product):
objects = ProductManager()

multiplier = models.DecimalField(max_digits=5,decimal_places=3)
profile_code = models.ForeignKey('Profile')
metal = models.ForeignKey('Metal')

def _get_subtype(self):
return 'Ring'

def __unicode__(self):
return u"Ring: %s" % self.name

class Admin:
pass

class Meta:
verbose_name = _('Ring')
verbose_name_plural = _('Rings')
</pre>

If I leave off _get_subtypes I get an attribute error, if I leave it
in I blow the stack off with the a max recursion error. It is getting
trapped in the following function call: add_template_context, and the
error is being called on this line "context =
subtype.add_template_context(context, *args, **kwargs)" (line 1098 in
product/models.py). I have tried to glean an understanding of what the
subtype is used for by going through the code, but I have to admit I'm
stumped as to how to fix the problem.

Bob Waycott

unread,
May 4, 2009, 12:29:05 PM5/4/09
to satchm...@googlegroups.com
Benjamin,

What is the purpose you are trying to achieve with _get_subtype()? And what is the AttributeError you receive when you leave it out?

Thanks,

Bob

Benjamin Edwards

unread,
May 6, 2009, 5:19:44 PM5/6/09
to Satchmo users
Hi,

The error I get is the following:

AttributeError at /admin/jewellery/ring/add/

'Ring' object has no attribute '_get_subtype'

Hence why I tried adding in my own subtype. To be honest, I am not
trying to achieve anything other than to make the error go away :)
Having had a look at the satchmo source code though, I did get to
thinking that subtypes might be a good way to use custom views for
certain product types further on down the line, but in this particular
instance I don't think I will need that.

On May 4, 5:29 pm, Bob Waycott <bobwayc...@gmail.com> wrote:
> Benjamin,
> What is the purpose you are trying to achieve with _get_subtype()? And what
> is the AttributeError you receive when you leave it out?
>
> Thanks,
>
> Bob
>
> On Mon, May 4, 2009 at 11:48 AM, Benjamin Edwards <benjuma...@googlemail.com

Bob Waycott

unread,
May 6, 2009, 8:29:19 PM5/6/09
to satchm...@googlegroups.com
Perhaps a complete Traceback would be more helpful.

Do you know where _get_subtype() is being called on the Ring object? If you find that, you will likely find your error. 

Bob Waycott

unread,
May 6, 2009, 8:31:56 PM5/6/09
to satchm...@googlegroups.com
The Traceback would still be useful ... but I neglected to take another look at your first post where you try to point out where the error is occurring. However, a complete Traceback, even if you just post it to pastebin or dpaste and give us a link here would at least give us more to look at.

Thanks.

Benjamin Edwards

unread,
May 11, 2009, 4:29:43 PM5/11/09
to Satchmo users
Hi, sorry! Have been slapped at work, haven't been able to dedicate
any time to this :( I really appreciate your time.

http://python.pastebin.com/f32359bfb

is the full trace back for the attribute error.

On 7 May, 01:31, Bob Waycott <bobwayc...@gmail.com> wrote:
> The Traceback would still be useful ... but I neglected to take another look
> at your first post where you try to point out where the error is occurring.
> However, a complete Traceback, even if you just post it to pastebin or
> dpaste and give us a link here would at least give us more to look at.
> Thanks.
>

Bob Waycott

unread,
May 12, 2009, 9:49:31 AM5/12/09
to satchm...@googlegroups.com
I'm still not understanding why you even have _get_subtype()

A couple things to point out ... you are receiving the error because Satchmo is trying to lookup Ring._get_subtype as an attribute ... but you have defined it as a method, which means it should be called as Ring._get_subtype(). If you don't know why you have it in there, then take it out. You should not need it -- particularly when you have no idea why its even in there. Never add a line of code to a project that you don't understand and know why it is there. ;)

So, my suggestion, unless you can explain your reason for having the method there, is to get it out of your Ring class. You're likely getting a max recursion error because you are returning the Ring class in _get_subtype() ... not something you want to do, and further shows that you don't really have a purpose for having it in there.

So ... cut it out and then let us know what kind of error you receive with a Traceback.

Thanks,

Bob

Benjamin Edwards

unread,
May 12, 2009, 4:09:42 PM5/12/09
to Satchmo users
Hey,

Thanks for the reply. I should have mentioned this in the previous
post, but I *did* get rid of the _get_sub_type method, for all of the
reasons you mentioned. I only put it in because not having it there
was giving me an error to start with! The trace back I posted was
using a model with no get sub types of any kind on it, like so:
http://python.pastebin.com/f7b558095 . That gave me the traceback
posted above.

On May 12, 2:49 pm, Bob Waycott <bobwayc...@gmail.com> wrote:
> I'm still not understanding why you even have _get_subtype()
> A couple things to point out ... you are receiving the error because Satchmo
> is trying to lookup Ring._get_subtype as an attribute ... but you have
> defined it as a method, which means it should be called as
> Ring._get_subtype(). If you don't know why you have it in there, then take
> it out. You should not need it -- particularly when you have no idea why its
> even in there. Never add a line of code to a project that you don't
> understand and know why it is there. ;)
>
> So, my suggestion, unless you can explain your reason for having the method
> there, is to get it out of your Ring class. You're likely getting a max
> recursion error because you are returning the Ring class in _get_subtype()
> ... not something you want to do, and further shows that you don't really
> have a purpose for having it in there.
>
> So ... cut it out and then let us know what kind of error you receive with a
> Traceback.
>
> Thanks,
>
> Bob
>
> On Mon, May 11, 2009 at 4:29 PM, Benjamin Edwards <benjuma...@googlemail.com
Reply all
Reply to author
Forward
0 new messages