Q:

Django DetailView for two seperate queries / models

I have a working detailview for my orders and wanted to add another queryset(for model Entry) to it to be able to read out some more data to the user, that I don't have stored in the orders model. 
What will be the best way to attack that since both models share the same foreignkey Cart? 
I suppose something in the direction of: entry_obj = Entry.objects.filter(cart=Order.objects.cart)? But how to implement it into the detailview?
url(r'^(?P<order_id>[0-9A-Za-z]+)/$', views.OrderDetailView.as_view(),
    name="detail"),

class OrderDetailView(LoginRequiredMixin, DetailView):
    def get_object(self):
        qs = Order.objects.by_request(
            self.request
            ).filter(order_id = self.kwargs.get('order_id'))
        if qs.count() == 1:
            return qs.first()
        return Http404

Models.py
class Entry(models.Model):
    product = models.ForeignKey(Product, null=True)
    cart = models.ForeignKey(Cart, null=True)
    fabric = models.ForeignKey(Fabric, null=True)
    quantity = models.PositiveIntegerField()

Models.py
class Order(models.Model):
    billing_profile = models.ForeignKey(BillingProfile, null=True, blank=True)
    order_id        = models.CharField(max_length=120, blank=True)
    shipping_address= models.ForeignKey(Address, related_name="shipping_address",
                                        null=True, blank=True)
    cart            = models.ForeignKey(Cart)
    total           = models.DecimalField(default=0.00, decimal_places=2,
                        max_digits=100)
    active          = models.BooleanField(default=True)

Thanks for help!

A:

You can override get_context_data for this:
class OrderDetailView(LoginRequiredMixin, DetailView):
    def get_object(self):
        qs = Order.objects.by_request(
            self.request
            ).filter(order_id = self.kwargs.get('order_id'))
        if qs.count() == 1:
            return qs.first()
        return Http404

    def get_context_data(self, **kwargs):
        context = super(OrderDetailView, self).get_context_data(**kwargs)
        context['entry_obj'] = Entry.objects.filter(cart=self.object.cart)
        return context

In template you'll be able to get entry details like this:
{{ entry_obj.quantity }}

