Skip to main content
Common questions and solutions for Ralph developers.

Admin and Views

Single extra view classes cannot be reused across multiple admin sites. Each admin site requires its own instance of the extra view class.Problem:
Solution: Create a separate class for each admin site, even if they inherit from the same base:
Real-world example: The Attachments app demonstrates this pattern. For every admin site using AttachmentsMixin, a separate AttachmentsView class is created.See ralph/attachments/admin.py for implementation examples.
By default, the front dashboard doesn’t show “Hardware loan”, “Hardware release”, or “Hardware return” boxes. These boxes appear only when you have assigned assets in specific states.Requirements:
  • Asset must be in ‘in progress’ or ‘in use’ state
  • Asset must be assigned to the current user
  • Transition IDs must be configured in settings
Setup steps for empty database:
  1. Create the database and superuser:
  2. Create a transition:
    • Navigate to: http://localhost:8000/transitions/transitionmodel/1/
    • Click [add another transition]
    • Set:
      • Source: ‘in progress’
      • Destination: ‘in use’
    • Click [Save]
  3. Find the transition ID:
    Note the id value (e.g., 1)
  4. Configure settings: Add to settings/dev.py:
    Replace 1 with your actual transition ID.
  5. Create test assets: Navigate to http://localhost:8000/back_office/backofficeasset/add/ and create assets with:
    • Status: ‘in progress’
    • Assigned to user: r2
    • Owner: r2 Repeat with statuses ‘return in progress’ and ‘loan in progress’.
  6. View dashboard: Open incognito mode and login as user r2 to see the dashboard boxes.
This error occurs when transition IDs are not properly configured:
Solution: Configure the transition IDs in your settings file as shown in the previous FAQ item.

API Development

Create API endpoints using Ralph’s base classes:
The endpoint will be available at /api/my-models/.See API Documentation for advanced features.
Use select_related and prefetch_related in your ViewSet:
Tip: Check the Django Debug Toolbar or use django.db.connection.queries to identify N+1 queries.
Ralph provides multiple filtering options:1. Simple field filtering:
Usage: /api/my-models/?name=test&status=active2. Lookup filtering (automatic): Usage: /api/my-models/?name__startswith=test&created_date__gte=2024-01-013. Extended filters for polymorphic models:
Usage: /api/my-models/?name=test searches all specified fields4. Custom filter backend:
Use the save_serializer_class attribute:
Now:
  • GET requests return nested objects
  • POST/PUT/PATCH requests accept IDs

Models and Database

Override the clean() method:
This validation will run:
  • In Django admin forms
  • In API requests (if using RalphAPISerializer)
  • When calling full_clean() or save() with validation
After modifying models:
Best practices:
  • Review generated migrations before committing
  • Add data migrations for complex changes
  • Test migrations on a copy of production data
  • Never modify applied migrations
Ralph supports custom fields through the Custom Fields framework:
  1. Enable custom fields in admin:
  2. Custom fields are automatically available in API
  3. Access in code:
See Custom Fields Documentation for details.

Testing

Use Ralph’s test utilities:
Ralph uses factory_boy for test data:

Deployment and Configuration

Ralph uses Django’s settings system with environment-specific files:
  • settings/base.py - Base settings
  • settings/dev.py - Development overrides
  • settings/prod.py - Production overrides
  • settings/test.py - Test overrides
Override settings: Create settings/local.py:
Use environment variables:
Never enable DEBUG in production!For development:
For production debugging:
  • Use logging instead of DEBUG=True
  • Configure Sentry or similar error tracking
  • Use Django’s logging framework
Configure in settings:
Use in code:

Performance and Optimization

Using Django Debug Toolbar:
Using query logging:
Using django-silk:
Add to settings and visit /silk/ for profiling UI.
Use pagination:
Use iterator for large datasets:
Use only() and defer():
Use values() for simple data:

Need More Help?

If your question isn’t answered here: