Hi

I have a shopping cart application, where by each cart can hold
several kinds of objects,  I have therefore used generic relations to
model the application along the lines of below, whereby each cart can
have many cartitems which are linked by a standard foreign key
relationship, the cartitems are in turn linked to the individual item
models by a GenericForeignKey:

class Cart(models.Model):
        invoice = models.PositiveIntegerField(max_length=50, null=True,
unique=True)
        datetime_added = models.DateTimeField(auto_now_add=True)
        ....etc

class CartItem(models.Model):
        content_type = models.ForeignKey(ContentType)
        object_id = models.PositiveIntegerField()
        content_object = generic.GenericForeignKey('content_type',
'object_id')
        cart = models.ForeignKey(Cart, related_name="items")

class AccessoryOrder(models.Model):
       cart_item = generic.GenericRelation(CartItem)

class BikePart(UsedItem):
        partType = models.ForeignKey(PartType)
        cart_item = generic.GenericRelation(CartItem)

class UsedBike(UsedItem):
        bike = models.ForeignKey(Bike)
        cart_item = generic.GenericRelation(CartItem)

This works fine, but I can't figure out a way to get what I want in
the admin app.  I have created the AccessoryOrderInline class
subclassing GenericStackedInline, but the inlines don't work in
reverse even where you have added the generic.GenericRelation
attribute to the model. The relevant parts of admin.py are:

class AccessoryOrderInline(generic.GenericStackedInline):
        model = AccessoryOrder

class CartItemInline(admin.StackedInline):
        model = CartItem
        exclude = ('content_type', 'object_id')
        extra = 0
        fields = ('content.object',)
        inlines = [
                        AccessoryOrderInline,
        ]

class CartAdmin(admin.ModelAdmin):
        date_hierarchy = 'datetime_added'
        form = CartForm
        inlines = [
                        CartItemInline,
        ]

The issue is that when I click on a cart to view in admin, I the
CartItem objects but not the Accessory objects themselves,  or any
other types of item.  With the model design the way it is, I don't see
a way of getting the admin app to do what I want,  so is my model
design flawed and is there a better way of doing this using generic
relations.

Thanks

Simon

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

Reply via email to