@@ -22,7 +22,7 @@ is a framework for building e-commerce sites on top of
2222source under a
2323[ custom license written by Tangent Communications PLC] ( https://github.com/django-oscar/django-oscar/blob/master/LICENSE ) .
2424
25- [ ** django-oscar/ src/ oscar/ apps/ address/ admin.py** ] ( https://github.com/django-oscar/django-oscar/blob/master/src/oscar/apps/address/admin.py )
25+ [ ** django-oscar / src / oscar / apps / address / admin.py** ] ( https://github.com/django-oscar/django-oscar/blob/master/src/oscar/apps/address/admin.py )
2626
2727``` python
2828# admin.py
@@ -64,7 +64,7 @@ backend that displays
6464code is open source under the
6565[ MIT license] ( https://github.com/Michael-Cantley/heritagesites/blob/master/LICENSE ) .
6666
67- [ ** heritagesites/ heritagesites/ admin.py** ] ( https://github.com/Michael-Cantley/heritagesites/blob/master/heritagesites/admin.py )
67+ [ ** heritagesites / heritagesites / admin.py** ] ( https://github.com/Michael-Cantley/heritagesites/blob/master/heritagesites/admin.py )
6868
6969``` python
7070# admin.py
@@ -209,3 +209,90 @@ class Location(admin.ModelAdmin):
209209 list_display = [' planet' , ' region' , ' sub_region' , ' intermediate_region' ]
210210 ordering = [' planet' , ' region' , ' sub_region' , ' intermediate_region' ]
211211```
212+
213+
214+ ## Example 3 from viewflow
215+ [ viewflow] ( https://github.com/viewflow/viewflow )
216+ ([ project website] ( http://viewflow.io/ ) ) is a reusable workflow
217+ code library for organizing business logic in complex web applications.
218+ The code for the project is available under the
219+ [ GNU Alfredo license] ( https://github.com/viewflow/viewflow/blob/master/LICENSE ) .
220+
221+ [ ** viewflow / viewflow / admin.py** ] ( https://github.com/viewflow/viewflow/blob/master/viewflow/admin.py )
222+
223+ ``` python
224+ # admin.py
225+ ~~ from django.contrib import admin, auth
226+ from viewflow.models import Process, Task
227+
228+
229+ ~~ class TaskInline (admin .TabularInline ):
230+ """ Task inline."""
231+
232+ model = Task
233+ fields = [' flow_task' , ' flow_task_type' , ' status' ,
234+ ' token' , ' owner' ]
235+ readonly_fields = [' flow_task' , ' flow_task_type' , ' status' ,
236+ ' token' ]
237+
238+ def has_add_permission (self , request ):
239+ """ Disable manually task creation."""
240+ return False
241+
242+ def has_delete_permission (self , request , obj = None ):
243+ """ Disable task deletion in the process inline."""
244+ return False
245+
246+
247+ ~~ class ProcessAdmin (admin .ModelAdmin ):
248+ """ List all of viewflow process."""
249+
250+ icon = ' <i class="material-icons">assignment</i>'
251+
252+ actions = None
253+ date_hierarchy = ' created'
254+ list_display = [' pk' , ' created' , ' flow_class' , ' status' ,
255+ ' participants' ]
256+ list_display_links = [' pk' , ' created' , ' flow_class' ]
257+ list_filter = [' status' ]
258+ readonly_fields = [' flow_class' , ' status' , ' finished' ]
259+ inlines = [TaskInline]
260+
261+ def has_add_permission (self , request ):
262+ """ Disable manually process creation."""
263+ return False
264+
265+ def participants (self , obj ):
266+ """ List of users performed tasks on the process."""
267+ user_ids = obj.task_set.exclude(owner__isnull = True ).\
268+ values(' owner' )
269+ USER_MODEL = auth.get_user_model()
270+ username_field = USER_MODEL .USERNAME_FIELD
271+ users = USER_MODEL ._default_manager.filter(pk__in = user_ids).\
272+ values_list(username_field)
273+ return ' , ' .join(user[0 ] for user in users)
274+
275+
276+ ~~ class TaskAdmin (admin .ModelAdmin ):
277+ """ List all of viewflow tasks."""
278+
279+ icon = ' <i class="material-icons">assignment_turned_in</i>'
280+
281+ actions = None
282+ date_hierarchy = ' created'
283+ list_display = [' pk' , ' created' , ' process' , ' status' ,
284+ ' owner' , ' owner_permission' , ' token' ,
285+ ' started' , ' finished' ]
286+ list_display_links = [' pk' , ' created' , ' process' ]
287+ list_filter = [' status' ]
288+ readonly_fields = [' process' , ' status' , ' flow_task' , ' started' ,
289+ ' finished' , ' previous' , ' token' ]
290+
291+ def has_add_permission (self , request ):
292+ """ Disable manually task creation."""
293+ return False
294+
295+
296+ ~~ admin.site.register(Process, ProcessAdmin)
297+ ~~ admin.site.register(Task, TaskAdmin)
298+ ```
0 commit comments