Client Categorization Feature¶
Overview¶
This feature adds the ability to designate specific clients to be
displayed on the public /clients/ page and categorize them into
groups like Government, Non-profit, Private Sector, etc.
Changes Made¶
1. Model Changes (db/models.py)¶
Added
featuredboolean field to theClientmodelDefault:
FalseHelp text: “Check to display this client on the public clients page”
Added
categoryfield with predefined choices:Government
Non-Profit
Private Sector
Education
Healthcare
Other
The
ClientCategoryenum is defined as a nested class in theClientmodel
2. Database Migration (db/migrations/0002_client_featured_category.py)¶
Creates migration to add both
featuredandcategoryfieldsThe migration is compatible with the MongoDB backend used by the project
3. Form Changes (db/forms.py)¶
Updated
ClientFormto include:featuredfieldcategoryfield
Added these fields to the form layout
4. Admin Changes (db/admin.py)¶
Enhanced
ClientAdminwith:list_displayshowing name, company, category, and featured statuslist_filterfor filtering by featured status and categorysearch_fieldsfor searching by client name or company name
5. View Changes (cms/views.py)¶
Updated
ClientsViewto:Filter only
featured=TrueclientsGroup clients by their category
Pass a
categoriesdictionary to the templateEach category key maps to a list of clients in that category
6. Template Changes (cms/templates/blocks/clients_block.html)¶
Fixed the URL check to use
client.urlinstead ofclient.linkThe template already supports displaying clients grouped by categories
7. Tests (db/tests/test_client_categorization.py)¶
Added comprehensive test coverage:
Test featured field default value
Test category choices
Test category display names
Test filtering featured clients
Test grouping clients by category
Test the ClientsView context data
How to Use¶
1. Apply the Migration¶
python manage.py migrate db
2. Mark Clients as Featured¶
In the Django admin at /admin/db/client/: 1. Edit a client record 2.
Check the “Featured” checkbox 3. Select a category from the dropdown 4.
Save the client
3. View Featured Clients¶
Visit /clients/ to see the featured clients grouped by category.
Example Usage¶
# Create a featured government client
client = Client.objects.create(
name="US Department of Example",
featured=True,
category=Client.ClientCategory.GOVERNMENT,
url="https://example.gov"
)
# Query all featured clients
featured_clients = Client.objects.filter(featured=True)
# Query clients by category
gov_clients = Client.objects.filter(
featured=True,
category=Client.ClientCategory.GOVERNMENT
)
# Get display name for category
display_name = client.get_category_display() # Returns "Government"
Testing¶
Run the tests with:
python manage.py test db.tests.test_client_categorization
Or with pytest:
pytest db/tests/test_client_categorization.py
Notes¶
Non-featured clients (featured=False) will NOT appear on the public clients page
Clients without a category will be grouped under “Other”
The feature is backward compatible - existing clients default to featured=False
The admin interface provides easy filtering and searching capabilities