Friday, April 22, 2011

extending a shopping cart

say for instance you had a CartItem that was laid out pretty much as
follows

class CartItem(models.Model):
cart_id = models.CharField(max_length=50)
date_added = models.DateTimeField(auto_now_add=True)
quantity = models.IntegerField(default=1)
size = models.CharField(max_length=20)
product = models.ForeignKey('shop.Product', unique=False)

and you extended the shop to include products that can be found in
different apps, eg shop.Product as well as farm.Product
This has been done because the two Product models are vastly different
and so can't coexist in the same table.

is there a simple way of splitting the product out such that i can
refer to it as app and product, maybe by storing the app and the id?


class CartItem(models.Model):
cart_id = models.CharField(max_length=50)
product_app = models.CharField(max_length=50)
product_type = models.CharField(max_length=50)
product_id = models.CharField(max_length=50)

and if there is, how would i go about doing the following step:

p = get_object_or_404(Product, product_slug=product_slug)

im guessing there will need to be an intermediate step of

model = get_model(product_app, product_type)
p = get_object_or_404(model, id=product_id)


surely there is a far simpler cleverer way fo doing this? what do i
need to be reading about to do this?

--
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 django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate