Questions tagged [django-select-related]

Django operator, which returns a queryset that follows and caches foreign key relationships, in order to avoid hitting the database in future calls that require use of foreign keys.

147 questions
0
votes
1 answer

Django foreign keys in extra() expression

I'm trying to use the Django extra() method to filter all the objects in a certain radius, just like in this answer: http://stackoverflow.com/questions/19703975/django-sort-by-distance/26219292 but I'm having some problems with the 'gcd' expression…
0
votes
1 answer

select related and Q objects on already filtered queryset

I have a queryset that I get. Then depending on if certain things are true in my software I further filter the queryset. venuelist = Venue.objects.filter(approved=True, online=True) # intial queryset then if things are true or not I filter…
user9487981
0
votes
0 answers

Showing related items to the same model on detail page

I'm working on the News model. I have a list page and a detail page. I need on the detail page with the option of selecting other related news in the admin panel and saving them on the site. My model: class News(models.Model): title =…
user9192656
  • 549
  • 3
  • 16
0
votes
0 answers

Use select_related and prefetch_related

These are my two classes of the model class class UserProfile(models.Model): user=models.OneToOneField(User) profile_pic=models.ImageField(upload_to='profilepics/%Y/%m/%d/',default='\LoginPage\images\default.jpg') def __unicode__(self): …
0
votes
1 answer

How to get all related objects in django model ForeignKey and OneToOneField

I'm using django 1.9. I have the following Django models: @python_2_unicode_compatible class Projects(models.Model): index = models.IntegerField(blank=True,default=1) year = models.CharField(max_length=255, blank=True) title =…
0
votes
2 answers

Use select_related for comma separated field

I have two class model like this: class Problem(models.Model): owner = models.ForeignKey(User) services = models.CommaSeparatedIntegerField(max_length=200) class Services(models.Model): name = models.CharField(max_length=50) ... As…
Saber Solooki
  • 1,182
  • 1
  • 15
  • 34
0
votes
1 answer

Django Select Related

i want to filter the database like this . qs = profile.objects.filter().select_related('profile_detail').select_related('location') But here location is a foreignkey in profile_detail model. So how can i do that query class…
Thameem
  • 3,426
  • 4
  • 26
  • 32
0
votes
1 answer

Django: how to query relations effectively

I have a model "Booking" referencing to another model "Event" with a foreign key. class Event(models.Model): title = models.CharField(_("title"), max_length=100) class Booking(models.Model): user = models.ForeignKey('auth.User', ...,…
0
votes
2 answers

Django, Select related, Average, ManyToMany field

Suppose i have clients in my model (model Client), and suppose each client has a shopping cart (model Cart). Each cart has many items (model CartItems), then to finish, each item has a relation with one product (model Product). Now, here goes my…
thiag0ms
  • 17
  • 6
0
votes
1 answer

Django select related

I want to display all categories with related merchants and related merchant's image. How can I do this? models.py class Category(models.Model): title = models.CharField(max_length = 50) class Meta: verbose_name_plural =…
Alex Pavlov
  • 571
  • 1
  • 7
  • 24
0
votes
1 answer

Django ajax response model

I need to get data in template. I have ajax request: $(".retailer-list-img").mouseover(function () { var $this = $(this); var category_id = $this.attr('id'); $.ajax({ 'url': '/shop/getfeatured/', 'method': 'POST', …
Alex Pavlov
  • 571
  • 1
  • 7
  • 24
0
votes
1 answer

How to implement join in django with postgres?

Basically , I have three tables BusinessCards ,BusinessCardsIdentifiers and Identifiers.Primary key of BusinessCards and Identifiers are stored into BusinessCardsIdentifiers . I want to find a way to write single query and find related data from all…
0
votes
1 answer

Django-selectable and autocomplete: Autocomplete does not work. Should I add my own JS?

I'm trying to use Django selectable on django.auth User. It returs JSON with users on selectable/organiser_app-userlookup/, but no autocomplete appears in input. I've registered selectable in INSTALLED_APPS: INSTALLED_APPS = ( ... …
ziuu
  • 346
  • 1
  • 3
  • 9
0
votes
2 answers

Django - show in template related class count filtered by parameter

I will give my models first and then write description. class Entry(models.Model): entry_text = models.TextField() class Category(models.Model): user = models.ForeignKey(User) category_text = models.CharField(max_length=200) entries…
wildd
  • 15
  • 4
0
votes
2 answers

Django: How can I join QuerySets from different models that are connected with a ForeignKey?

I want to combine attributes from two different models, which are connected with a ForeignKey, in one QuerySet to display them together in a table. I tried to join them with select_related, however, the attribute from model B does not appear in my…
1 2 3
9
10