Login

5 snippets

Snippet List

Form field with fixed value

In case you need a form field that only has one acceptable value, you can create a custom form field derived from `forms.ChoiceField` which only accepts one choice. Alternatively you can: * Ignore the value of such a field entirely. * Simply pass a single choice to a the `forms.ChoiceField`

  • forms
  • field
Read More

Add Toggle Switch Widget to Django Forms

Implementation Suggestions use: ``` ....... widgets = { ...... }), 'solicitada_mpu': ToggleSwitchWidget(size='sm', active_color='#9333ea', inactive_color='#ccc', active_text='YES', inactive_text='NO' ), ............... ```

  • ToggleSwitchWidget
  • toggle-switches
Read More

get_object_or_none

This utility is useful when you want to safely retrieve a single object from the database without having to wrap get() in a try/except block every time. It also supports query optimization via select_related and prefetch_related, making it ideal for performance-conscious applications.

  • orm
  • queryset
  • utils
  • select_related
  • get_or_none
  • prefetch_related
Read More

Mask sensitive data from logger

This will help to secure the sensitive secrets, token, api keys, etc from logger. As we know there is security issue when we include the sensitive information to the logger in case logger got leaked/hacked. Before: ``` INFO ('192.168.1.1', 33321) - "WebSocket /ssh?token=abcdefg&width=20&heigh20" ``` After: ``` INFO ('192.168.1.1', 33321) - "WebSocket /ssh?token=********&width=20&heigh20" ```

  • django
  • security
  • logging
  • logger
Read More