I'm reposting this from another thread, hoping it will help ... I can
respond to Ryan's other concerns later.
*****

If I define my custom product like so:

CustomProduct(Product):
  special_field = models.CharField()
  special_field2 = models.BooleanField()

and I save it, I can do anything with it that I can do with a Product.

So, give CustomProduct instance with an id of 3, as in your example, I will
be editing the same product at both of these URLs:

http://127.0.0.1:8000/admin/product/product/3/<http://127.0.0.1:8000/admin/special_product/myproduct/3/>

http://127.0.0.1:8000/admin/special_product/myproduct/3/

The only difference will be that editing via the standard /admin/product/
URL will not provide the extra fields I get at /admin/special_product/

If I haven't modified the admin form used for my CustomProduct when I
registered it, I should still have all standard Product fields available,
including `slug`. `slug` is used for the URLs. So, if my CustomProduct.slug
is "my_custom_product", I should see my custom product via the default
Satchmo URLs & templates at this URL:

http://127.0.0.1:8000/shop/product/my_custom_product/<http://127.0.0.1:8000/shop/product/dj-rocks/>

This should work right out of the box because the saved instance of
CustomProduct is an instance of Product. So, if I was hacking around at the
shell, I can do this:

>> c = CustomProduct.objects.get(pk=3)
>> p = Product.objects.get(pk=3)
>> c.slug
u'my_custom_product'
>> p.slug
u'my_custom_product'
>> c.id
3
>> p.id
3
>> c.name
u'My Custom Product'
>> p.name
u'My Custom Product'

As you can see, the data is the same.

Now, what if I want to access the CustomProduct's special attributes via the
Product instance? (After all, the Product instance is what is returned by
the default Satchmo views if I don't write a custom view for it). Via the
shell, again:

>> p
<Product: My Custom Product>
>> p.custom_product
<CustomProduct: My Custom Product>

(This, of course assumes you defined CustomProduct.__unicode__() to return
self.name)

So, you get to your inherited CustomProduct via the Product instance by way
of Django's related syntax. Given my model definition above, I can now do
this from my Product instance:

>> p.custom_product.special_field
u'Here's a special CharField'
>> p.custom_product.special_field2
True

So what if I wanted to modify Satchmo's templates to provide this
information on viewing? It's just as simple:

{{ product.custom_product.special_field }}

{{ product.custom_product.special_field2 }}

Now, if you want to get even fancier with a bunch of custom business logic
that is attached to your CustomProduct instance, the proper place for that
is views. DO NOT modify Satchmo's views. Instead, write a custom view that a
urlpattern points to and handle your CustomProduct logic there.

It is infinitely extensible and ensures that changes to Satchmo don't mean
changes to your custom handling of products.

Hope this helps. Feel free to ask for more clarification if needed. I've
been realizing for a while that I should make another post to the Satchmo
diaries going over this subject for people that aren't used to it. I will
try to write up something more in-depth as soon as possible and get it
online.

Best,

Bob Waycott

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

Reply via email to