schinckel / django-computed-field Goto Github PK
View Code? Open in Web Editor NEWComputedField() for django
License: MIT License
ComputedField() for django
License: MIT License
Hi,
Python setup.py install seems not to play nicely with virtualenvs.
The package is installed and the script runs, but Pycharm thinks it's missing
Python 3.6
Hi !
Thanks for the great work ! A great addition to Django !
I've an issue that is probably a relatively common deal breaker.
When using models.Subquery in the annotation, I get an Models aren't loaded yet.
exception .
I guess this could be solved by allowing to wrap the expression in a callable, so that it could be evaluated lazily.
Here's the (simplified) code I'm trying to adapt to the library :
class Work(models.Model):
task = models.ForeignKey("Task", on_delete=models.PROTECT)
date = models.DateField()
hours_done = models.FloatField()
class TaskManager(models.Manager):
def get_queryset(self):
qs = super().get_queryset()
qs = qs.annotate(total_hours_done=models.Subquery(
Work.objects.filter(task=OuterRef("pk"))
.values("task")
.order_by()
.annotate(total=Sum("hours_done"))
.values("total"),
output_field=models.FloatField(),
))
return qs
class Task(models.Model):
objects = TaskManager()
name = models.CharField(max_length=255)
I adapted it like this :
class Task(models.Model):
name = models.CharField(max_length=255)
total_hours_done = ComputedField(
models.Subquery(
Work.objects.filter(task=OuterRef("pk"))
.values("task")
.order_by()
.annotate(total=Sum("hours_done"))
.values("total"),
output_field=models.FloatField(),
)
)
What about renaming computed
to annotation
, both in the package name and the class name ?
I think it's more accurate, and also will prevent confusion with the different django-computedfields package (which is already on PyPi).
Thanks !
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.