0

For example, the Invoice model has a project field that points a ForeignKey to the Project model, Project has a custom ProjectManager that has get_queryset defined, in get_queryset I do: super().annotate(display=...)

and when I want to get this annotated field through Invoice: Invoice.objects.filter(project__display__iregex=...) then an error occurs that project does not have a display field, how can I make it so that the related models take fields from some queryset, this is get_queryset() for us

  • Django 4.2.4
  • Python 3.10

To take annotated fields I use Subquery:

Subquery(models.Project.objects.filter(id=OuterRef("project_id")).values_list("display"))

but because of this the request is executed very slowly.

3
  • You need to move on to update Django 5.0 and Python 3.12.5 or 3.14.0. Commented Aug 28, 2024 at 11:54
  • @toyotaSupra You seem to mean using ComputedField in Django 5, but is there an alternative as a library for Django 4? Commented Aug 28, 2024 at 15:31
  • When new Python 3. 12. Django 4 will not work. When the newer version will work, not, not the older version such as Python and Django. Commented Aug 28, 2024 at 15:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.