morlandi / django-ajax-datatable

A Django app which provides the integration of a Django project with the jQuery Javascript library DataTables.net
MIT License
208 stars 64 forks source link

You shouldn't do this in the class declaration: #12

Closed samerda75 closed 3 years ago

samerda75 commented 3 years ago

You shouldn't do this in the class declaration:

Rec_Count = model.objects.all().count()
if Rec_Count > 500:
    length_menu = [[10, 25, 50, 100], [10, 25, 50, 100]]
else:
    length_menu = [[10, 25, 50, 100, -1], [10, 25, 50, 100, _("All")]]

since RecCount would be evaluated only once when the file is imported. I would rather override get_length_menu as follows:

def get_length_menu(self):
    Rec_Count = model.objects.all().count()
    if Rec_Count > 500:
        length_menu = [[10, 25, 50, 100], [10, 25, 50, 100]]
    else:
        length_menu = [[10, 25, 50, 100, -1], [10, 25, 50, 100, _("All")]]
    return self.length_menu

Did you encounter other problems?

Originally posted by @morlandi in https://github.com/morlandi/django-ajax-datatable/issues/11#issuecomment-792516477

samerda75 commented 3 years ago

thank you for your reply it is useful, But this did not solve my original point, which i would like to show the date range filter fields

samerda75 commented 3 years ago

it will be appreciated if you can assist me to resolve this issue

morlandi commented 3 years ago

I do believe that the "example"django project in this library, also published here:

http://django-ajax-datatable-demo.brainstorm.it/

already has a working date range filter. I suggest you to check the sources and compare them with your own project

samerda75 commented 3 years ago

If I right click and view source code it doesn’t show the full code

Samer Daghestani

CEO

m. 05398926163e. @.***

This electronic message transmission contains information which may be confidential or privileged. The information is intended to be for the use of the individual or entity named above. If you are not the intended recipient, be aware that any disclosure, copying, distribution or use of the contents of this information is prohibited. If you have received this electronic transmission in error, please notify us by electronic mail @.*** immediately.

From: morlandi @.> Reply-To: morlandi/django-ajax-datatable @.> Date: Tuesday, March 9, 2021 at 7:39 PM To: morlandi/django-ajax-datatable @.> Cc: samerda75 @.>, Author @.***> Subject: Re: [morlandi/django-ajax-datatable] You shouldn't do this in the class declaration: (#12)

I do believe that the "example"django project in this library, also published here:

http://django-ajax-datatable-demo.brainstorm.it/

already has a working date range filter. I suggest you to check the sources and compare them with your own project

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

morlandi commented 3 years ago

@samerda75 the source code for the demo project is already in the library. Download it all from Github, then check in the "example" subfolder