Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Linux Kernel 3.9.6 / 3....
  • Linux Kernel 3.0.82 LTS...
  • KDE Software Compilatio...
  • PulseAudio 4.0
  • Wireshark 1.10.0
  • NetworkManager 0.9.8.2
  • LibreOffice 3.6.6 / 4.0...
  • SystemRescueCd 3.7.0
  • Linux Kernel 3.10 RC6
  • Ubuntu Tweak 0.8.5
  • Home > Linux > Internet > Django Plugins

    django-generic-aggregation 0.3.2

    Download button

    No screenshots available
    Downloads: 188  View global page NEW!  Tell us about an update
    User Rating:
    Rated by:
    NOT RATED
    0 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Charles Leifer | More programs
    MIT/X Consortium Lic... / FREE
    May 3rd, 2012, 21:57 GMT
    ROOT / Internet / Django Plugins

     Read user reviews (0)  Refer to a friend  Subscribe

    django-generic-aggregation description

    annotate() and aggregate() for generically related data

    django-generic-aggregation provides annotate() and aggregate() for generically-related data.

    Examples

    You want the most commented on blog entries:

    >>> from django.contrib.comments.models import Comment
    >>> from django.db.models import Count
    >>> from blog.models import BlogEntry
    >>> from generic_aggregation import generic_annotate

    >>> annotated = generic_annotate(BlogEntry.objects.all(), Comment.content_object, 'id', Count)

    >>> for entry in annotated:
    ... print entry.title, entry.score


    The most popular 5
    The second best 4
    Nobody commented 0


    You want to figure out which items are highest rated:

    from django.db.models import Sum, Avg

    # assume a Food model and a generic Rating model
    apple = Food.objects.create(name='apple')

    # create some ratings on the food
    Rating.objects.create(content_object=apple, rating=3)
    Rating.objects.create(content_object=apple, rating=5)
    Rating.objects.create(content_object=apple, rating=7)

    >>> aggregate = generic_aggregate(Food.objects.all(), Rating.content_object, 'rating', Sum)
    >>> print aggregate
    15

    >>> aggregate = generic_aggregate(Food.objects.all(), Rating.content_object, 'rating', Avg)
    >>> print aggregate
    5


    Check the tests - there are more examples there. Tested with postgres & sqlite


    Product's homepage

    Requirements:

    · Python
    · Django

      


    TAGS:

    generic aggregation | Django aggregation | annotate() | aggregate() | Django

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM