This is a bleeding-edge feature that I'm currently skewered upon and quickly bleeding out. I want to annotate a subquery-aggregate onto an existing queryset. Doing this before 1.11 either meant custom SQL or hammering the database. Here's the…
I'm having problems using annotate() with OuterRef in Django 1.11 subqueries. Example models:
class A(models.Model):
name = models.CharField(max_length=50)
class B(models.Model):
a = models.ForeignKey(A)
Now a query with a subquery (that…
An simplified example of my model structure would be
class Corporation(models.Model):
...
class Division(models.Model):
corporation = models.ForeignKey(Corporation)
class Department(models.Model):
division =…
I have recently upgraded to django 1.11 and I want to use the newly released, Subquery exrpession feature.
There are two models as follows
class Project(models.Model):
title = models.CharField(_("Project Name"), max_length=128)
class…
Please help me I've been stuck on this for way too long :(
What I want to do:
I have these two models:
class Specialization(models.Model):
name = models.CharField("name", max_length=64)
class Doctor(models.Model):
name =…
I have an Company and User models with a related model CompanyRecruiter:
class CompanyRecruiter(models.Model):
organization = models.ForeignKey(Company, related_name="company_recruiters")
recruiter = models.ForeignKey(User,…
Using django with a MySQL DB and given these models:
ModelB ---FK---> ModelA
- ref_type
- ref_id
ModelC
I want to get all the ModelC for each ModelA via an annotation.
I tried many options looking at existing solutions but could not…
I am working with Django 3.1 ORM and am running (with pytest) a test involving a complex nested query. I get this failure:
self =
lookup = 'lte'
def get_lookup(self,…
I have following Post, Category & PostScore Model.
class Post(models.Model):
category = models.ForeignKey('Category', on_delete=models.SET_NULL, related_name='category_posts', limit_choices_to={'parent_category': None}, blank=True, null=True)
…
I try to code the equivalent Django query from this SQL query, but I'm stuck.
Any help is welcome.
I receive a race id and from this race I want to do some statistics : nb_race = the number of races from a Horse before the race given, best_chrono =…
I have the below models:
class Group(models.Model):
group_name = models.CharField(max_length=32)
class Ledger(models.Model):
ledger_name = models.CharField(max_length=32)
group_name =…
I am trying to execute a complex Django query involving a nested subquery. Starting with the Stick model, I want to annotate the ownership_pct from the StickOwnership model (which is straightforward given the FK relationship). Next, I also want to…
I have 2 django models which aren't linked by ForeignKey due to legacy system.
class Parent(model):
name -> CharField()
class Child(model)
parent_name -> CharField()
cost -> IntegerField()
I want to achieve a left join which…
I have an app with models and db schema that looks as shown below. I am trying to add field r to L2 in order to be able to access the related objects from model R. The new field is not shown in the schema figure.
Retrieving the desired value of…