Hi Marks,
Ok, I would use `prefetch_related` method then.
https://docs.djangoproject.com/en/2.0/ref/models/querysets/#prefetch-related
you should override `get_queryset` with something like that:
def get_queryset(self, request):
return super().get_queryset(request).prefetch_related('document
should have been
class CollectionAdmin(admin.ModelAdmin)
in the above post.
Mark
On Sat, Dec 9, 2017 at 9:16 AM, Mark Phillips
wrote:
> Hit send by accident...
>
> Constantine,
>
> Thanks for the link and update! However, I am not sure how to make two
> columns in the CollectionsAdmin table wi
Hit send by accident...
Constantine,
Thanks for the link and update! However, I am not sure how to make two
columns in the CollectionsAdmin table without two functions.
class CollectionAdmin(self, obj):
list_display = ('get_field_1', 'get_field_2', )
def get_field_1(self, obj):
Constantine,
Thanks for the link and update! However, I am not sure how to make two
columns in the CollectionsAdmin table without two functions.
class COllectionAdmin(self, obj):
list_display =
On Sat, Dec 9, 2017 at 8:53 AM, Constantine Covtushenko <
constantine@gmail.com> wrote:
> Hi Mark
Hi Mark,
You should not create 2 methods.
Just change that first to be like:
return obj.document.all().values_list('field_1', 'field_2')
With this you will get QuerySet of tuples, like
I believe it should solve your problem.
Also for more references about values_list, check following document
Hi Mark,
Answering on your question I would do in your `get_documents` method:
return obj.document.all().values_list('title', flat=True)
this will get list of all document titles.
But at the same time why do you need get_documents method? How do you use
it?
May be it is better to optimize `get_
I have two models -
class Document(models.Model):
document_id = models.AutoField(primary_key=True)
title = models.CharField('title', max_length=200)
class Meta:
ordering = ['title']
def __str__(self):
return "%s" % (self.title)
class Collection(models.Model):
7 matches
Mail list logo