This is how you do it:
class ItemInline(admin.TabularInline):
    model = Category.items.through

class CategoryAdmin(admin.ModelAdmin):
    inlines = [
        ItemInline,
    ]
    exclude = ('items',)


On Oct 24, 9:48 pm, jenia ivlev <jenia.iv...@gmail.com> wrote:
> In the admin I want to use inline elements. I want category to display
> the items it is related to.
>
> But I get this error:
> Exception at /admin/store/category/7/
> <class 'store.models.Item'> has no ForeignKey to <class
> 'store.models.Category'>
>
> It's true, of-course, since I chose to use Category to point to the
> items it has.
> But, how can I get the admin to list in-line all the items that a
> given Category has?
> How can I get around this error?
>
> CONTEXT:
>
> class Category:
>     items=models.ManyToManyField(Item,through='Categoryhasitem')'
>
> class Categoryhasitem(models.Model):
>     category = models.ForeignKey(Category, db_column='category')
>     item = models.ForeignKey(Item, db_column='item')
>
> class Item(models.Model):
>     id = models.AutoField(primary_key=True)
>
> This is my admin.py file.
>
> class ItemInline(admin.TabularInline):
>     model=Item
> class CategoryAdmin(admin.ModelAdmin):
>     inlines=[ItemInline,]
> class ItemAdmin(admin.ModelAdmin):
>     pass
> admin.site.register(Category, CategoryAdmin)
> admin.site.register(Item, ItemAdmin)

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

Reply via email to