Tagged Questions
0
votes
1answer
7 views
Most common record in QuerySet Django
Hi how can I select records ordered by the most common record in Django.
My model is:
Action|User|Date
-----------------
sport |Mark|00/00/2000
study |Alex|00/00/2001
sport |Paul|00/00/2010
Sport ...
0
votes
1answer
23 views
Django filter() on field of related model
I think I'm missing something very basic and fundamental about how Django's filter() method is supposed to work.
Using the following models:
class Collection(models.Model):
pass
class ...
0
votes
0answers
13 views
exclude objects with foreignkey which is related with another object with a foreignkey when there are 0 objects in the relationship
I did'nt know how to ask the question, I'm going to try to explain what I want.
I have the next models:
class Thread(models.Model):
users = models.ManyToManyField(User, null=True,blank=True, ...
0
votes
0answers
7 views
Django: how to handle caching in views that differ for Ajax requests?
I have a Django application and a postgres backend. It's essentially a search site with a large database, and the data typically changes once a day. I would like to start caching, to reduce load on ...
0
votes
0answers
19 views
Django admin changelist - display latest value from related model as a sortable column
I have two models
class Product(models.Model):
sku = models.CharField(max_length=10, unique=True)
name = models.CharField(max_length=50)
...
class StockLevel(models.Model):
product = ...
0
votes
1answer
17 views
Sum two query set in django
I have two models, Quote and Post.
I want two send this to my template:
posts = Post.objects.order_by("-submitted_time")
quotes = Quote.objects.order_by("-submitted_time")
thing = posts + quotes
...
0
votes
1answer
21 views
Django related_table() with extra()
I'm trying to use .extra() function with .related_table():
foo_objects = Foo.objects.all()
result = foo.extra(select={'is_ok':'IF(bar.is_ok,"Yes","No")'}).select_related('bar')
Foo and Bar are ...
1
vote
2answers
24 views
How to pass one-to-many relationship to context on objects.all() lookup as iterable
I'm having trouble trying to wrap my head around this. many-to-one relationships are well documented, but I can't find an example on how to pass all of the relationships of a model.objects.all() ...
0
votes
0answers
25 views
Django models query parent objects issue
I have a question regarding models in Django.
I will explain how my models are structured. I have a model called AppUserGroup that is a group of users. This contains multiple users who I have called ...
0
votes
2answers
18 views
select_related or select_prefetched after calling filter()?
All the examples I see have select_related() first and then filter() call as in:
MyModel.objects.select_related().filter()
Can I do
qs = MyModel.objects.filter(my_field=my_var)
qs = ...
0
votes
1answer
18 views
Sorted list of two query sets
class TagSynonym(models.Model):
source_tag_name = models.CharField(max_length=255, unique=True)
target_tag = models.ForeignKey(Tag, related_name='tag_synonyms', null=True)
class ...
0
votes
1answer
35 views
Django ManyToMany relationship to queryset to pagination?
Here is the relevant code:
models.py
class Blog(models.Model):
...
images = models.ManyToManyField('myapp.Image')
class Image(models.Model):
...
title = ...
0
votes
2answers
16 views
How to query the object which has manytomany field point to them in django
I have two models User and Company
class Company(models.Model):
name = models.CharField max_length=50)
class User(models.Model):
name = models.CharField( max_length=40)
following = ...
1
vote
0answers
29 views
appending a queryset to a list/tuple without evaluating it
According to the docs a queryset gets evaluated when list() is called on it.
Is there a way to append a list/tuple with a queryset instead of model objects? Is list() called for every operation on ...
0
votes
0answers
26 views
Retrieve all related records using values_list or similar
I have 3 Models: Album, Picture and PictureFile, linked by Picture.album and Picture.pic_file
I'd like to do something like the following, and end up with a list of PictureFile records:
pic_files = ...