GithubHelp home page GithubHelp logo

atomos / django-admin-approx-count Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lqez/django-admin-approx-count

0.0 1.0 1.0 136 KB

A dirty mixin to rescue from dumb `count(*)` query of Django admin

License: MIT License

Python 100.00%

django-admin-approx-count's Introduction

django-admin-approx-count

A dirty mixin to rescue from dumb count(*) query of Django admin

What is this for?

Django admin works well with less set of rows.

But it slows down on large database system - every single list page of admin needs SELECT COUNT(*) FROM TABLE query to calculate the count of rows. And this causes severe performance issues on production system.

We don't really want to know EXACT count of rows. Right? Then use this.

See this Stackoverflow question

Installation

pip install django-admin-approx-count

or, download / clone from source repo

Usage

Use shipped mixins in your admin.py.

from django.contrib import admin
from approx_count.mixin import MaxIdAdminMixin, TableStatusAdminMixin

class SomeAdmin(MaxIdAdminMixin, admin.ModelAdmin):
    ...

class AnotherAdmin(TableStatusAdminMixin, admin.ModelAdmin):
    ...

Or, with admin classes.

from approx_count.admin import MaxIdModelAdmin, TableStatusModelAdmin

class SomeAdmin(MaxIdModelAdmin):
    ...

class AnotherAdmin(TableStatusModelAdmin):
    ...

Mixins

Default django queryset uses SELECT COUNT(*) FROM TABLE to calculate row count. However,

  • MaxIdAdminMixin uses SELECT MAX(ID) FROM TABLE.
  • TableStatusAdminMixin uses table status / information.

Note

Author

Park Hyunwoo(@lqez)

License

django-admin-approx-count is distributed under MIT license.

django-admin-approx-count's People

Contributors

lqez avatar

Watchers

 avatar

Forkers

axsapronov

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.