Currently you want to implement the function is to click on two links: in-service staff, leaving staff. Two pages are queried using the same listview.
The link for the first-in-service staff is
http://127.0.0.1/HRSystem/personlist/is_deleted-0
The link for the departing person is
Http://127.0.0.1/HRSystem/personlist/is_deleted-1
Is_deleted is the name of the field that is deleted in the model.
If you follow the links above, you can define urls.py:
urls.py from
hrsystem.views import Personlistview
to Django.contrib.auth import views as auth_views, Decorators
url (r ' ^personlist/([\w]+)-([\w]+)/$ ',
decorators.login_required (Personlistview.as_view (), Login_url= ' Hrsystem:login '),
name= ' personlist '),
The above uses the adorner login_require, if not logged in to visit the page, it will jump to the landing page.
Personlist class defined in views (omit references here)
views.py
class Personlistview (generic. ListView):
template_name = ' hrsystem/personlist.html '
paginate_by = +
def get_queryset (self,*args,** Kwargs):
person_list = Person.objects.filter (is_deleted=self.args[1])
return person_list
def get_ Context_data (Self,**kwargs):
context = Super (personlistview,self). Get_context_data (**kwargs)
return Context
It is worth noting that although the Is_deleted field uses Boonleanfield, true/false can not be substituted for 0 or 1 when URL access is used.
Self.args[] Gets the parameters in the URL.
If you do not want to pass parameters through args, you can use Kwargs to pass, but the URL is changed to:
URL (r ' ^personlist/(? p<a>[\w]+)-(? p<b>[\w]+)/$ ',
decorators.login_required (Personlistview.as_view (), login_url= ' Hrsystem:login ')
, Name= ' Personlist '),
Add parameter name A in the URL, b then in the reference to the views can be directly from the parameter name in the method to obtain
def get_queryset (Self,*args,**kwargs):
person_list = Person.objects.filter (is_deleted=self.kwargs[' B '])
Return person_list