Code Monkey home page Code Monkey logo

django-computed-field's People

Contributors

bashu avatar dependabot[bot] avatar schinckel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

django-computed-field's Issues

Virtualenv

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

`Models aren't loaded yet.` when annotating with models.Subquery

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(),
        )
    )

Rename to django-annotation-field

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 !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.