Reputation: 902
I am trying to show the orderitemsadmin
in the orderadmin
using TabularInline but I keep getting different errors like the following error.
AttributeError: 'OrderItemAdmin' object has no attribute 'urls'
and
django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'auth.User' that has not been installed
This is a Django e-commerce project and I am trying to facilitating the admin viewing the orders and their items.
I don't have much experience in using TabularInline that is why I am not able to do it corrrectly or what might be the mistake that I am doing.
Here is the admin.py
class OrderItemAdmin(admin.TabularInline):
list_display = ['item', 'quantity', 'ordered']
model = OrderItem
raw_id_fields = ['item']
class OrderAdmin(admin.ModelAdmin):
list_display = ['user', 'ordered', 'ordered_date', 'coupon', 'payment', 'shipping_address', 'status',
'refund_requested', 'refund_granted', 'ref_code']
inlines = [
OrderItemAdmin,
]
admin.site.register(OrderItem, OrderItemAdmin)
admin.site.register(Order, OrderAdmin)
Here is the models.py
class OrderItem(models.Model):
item = models.ForeignKey(Item, on_delete=models.CASCADE)
class Order(models.Model):
items = models.ManyToManyField(OrderItem)
Upvotes: 0
Views: 4696
Reputation: 160
you need to change your code to be like this
class OrderItemTabular(admin.TabularInline):
model = OrderItem
class OrderAdmin(admin.ModelAdmin):
list_display = ['user', 'ordered', 'ordered_date', 'coupon', 'payment', 'shipping_address', 'status',
'refund_requested', 'refund_granted', 'ref_code']
inlines = [
OrderItemTabular,
]
admin.site.register(Order, OrderAdmin)
first we create the tabular class which contains the model we want to show in our model , then we use this class in our model customization class OrderAdmin then we register our model with it's customization class
Upvotes: 1