Skip to content

Commit 90ce246

Browse files
author
Peter Kubov
committed
examples
1 parent adae8d2 commit 90ce246

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

docs/cores.rst

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,20 @@ Method ``per_save_model`` is called before saving object to database. Body is em
222222

223223
Method ``post_save_model`` is called after saving object to database. Body is empty by default.
224224

225+
**Example: Additional Processing After Save**
226+
227+
Use ``post_save_model`` to perform additional processing after an object is successfully saved::
228+
229+
class CustomerCore(DjangoUiRestCore):
230+
model = Customer
231+
232+
def post_save_model(self, request, obj, form, change):
233+
super().post_save_model(request, obj, form, change)
234+
235+
# Trigger communication for newly registered customers
236+
if not change: # Only for new customers
237+
trigger_customer_registered_communication(obj)
238+
225239
.. method:: DjangoCore.save_model(request, obj, form, change)
226240

227241
You can rewrite this method if you want to change way how is object saved to database. Default body is::
@@ -297,6 +311,21 @@ Every UI core has one place inside menu that addresses one of UI views of a core
297311
Option `show_in_menu` is set to ``True`` by default. If you want to remove core view from menu set this option to
298312
``False``.
299313

314+
**Example**
315+
316+
In production, you often have utility cores that shouldn't appear in navigation::
317+
318+
class CustomerImportCore(DjangoUiRestCore):
319+
"""Internal core for CSV import - not shown in menu"""
320+
model = Customer
321+
show_in_menu = False # Hidden from navigation
322+
menu_url_name = None # No menu link
323+
324+
class CustomerAuditLogCore(DjangoRestCore):
325+
"""API-only core for audit logs"""
326+
model = CustomerAuditLog
327+
show_in_menu = False # REST-only, no UI
328+
300329
.. attribute:: UiCore.view_classes
301330

302331
Option contains view classes that are automatically added to Django urls. Use this option to add new views. Example
@@ -317,6 +346,37 @@ you can see in section generic views (this is a declarative way if you want to r
317346
('reports', r'^/reports/$', MonthReportView),
318347
)
319348

349+
**Example**
350+
351+
In real-world applications, you often need to register many custom views with specific permissions::
352+
353+
class CustomerCore(DjangoUiRestCore):
354+
model = Customer
355+
356+
view_classes = (
357+
# Custom detail view with tabs
358+
('change', r'^/(?P<pk>[^/]+)/$', CustomerDetailView, False, False),
359+
360+
# Related object management
361+
('add-address', r'^/(?P<customer_pk>[^/]+)/address/add/$', AddressAddView, False, True),
362+
('edit-address', r'^/(?P<customer_pk>[^/]+)/address/(?P<pk>[^/]+)/$', AddressDetailView, False, False),
363+
364+
# Custom actions with parent scoping
365+
('activate', r'^/(?P<pk>[^/]+)/activate/$', CustomerActivateView, False, False),
366+
('deactivate', r'^/(?P<pk>[^/]+)/deactivate/$', CustomerDeactivateView, False, False),
367+
368+
# Bulk operations
369+
('bulk-export', r'^/bulk-export/$', CustomerBulkExportView, False, False),
370+
)
371+
372+
The tuple format is: ``(url_name_suffix, url_pattern, view_class, can_create, can_delete)``
373+
374+
- ``url_name_suffix``: Suffix added to core's base URL name
375+
- ``url_pattern``: Regular expression for URL matching
376+
- ``view_class``: The view class to use
377+
- ``can_create``: Boolean indicating if this view can create objects (default: False)
378+
- ``can_delete``: Boolean indicating if this view can delete objects (default: False)
379+
320380
.. attribute:: UiCore.default_ui_pattern_class
321381

322382
Every view must have assigned is-core pattern class. This pattern is not the same patter that is used with **django**

0 commit comments

Comments
 (0)