Skip to content

Instantly share code, notes, and snippets.

View jmorakuebler's full-sized avatar

Jordan Mora jmorakuebler

  • Asuncion, Paraguay
View GitHub Profile

Keybase proof

I hereby claim:

  • I am jmorakuebler on github.
  • I am jmorakuebler (https://keybase.io/jmorakuebler) on keybase.
  • I have a public key ASCBo0PFRnm0mAH3O0uk24P80DGpAEYlyys9ErK4HHrhtAo

To claim this, I am signing this object:

@jmorakuebler
jmorakuebler / get_field_verbose_name.py
Created November 13, 2019 13:11
Custom django template tag that returns the verbose name of a field.
from django.template import Library
register = Library()
@register.simple_tag
def get_field_verbose_name(instance, field_name):
"""Returns the verbose_name of the specified field."""
return instance._meta.get_field(field_name).verbose_name.title()
@jmorakuebler
jmorakuebler / custom_baseinlineformset.py
Last active April 23, 2020 14:08
Custom BaseInlineFormSet to check for duplicates in a inline formset
class CustomBaseInlineFormSet(BaseInlineFormSet):
"""
Custom BaseInlineFormSet with overridden clean method to look for
duplicates in the inline formset.
A message will appear under the offending field.
The field to be evaluated must be provided.
Attributes
field_name(string): name of the field to be verified. Default is None
msg (string): the message that will appear under the field. Default
@jmorakuebler
jmorakuebler / crispy_modelform_with_formhelper.py
Last active November 13, 2019 12:09
Custom ModelForm class with django-crispy-forms' FormHelper. You can optionally provide your own layout
from django.forms import ModelForm
from crispy_forms.helper import FormHelper
from crispy_forms.bootstrap import FormActions
from crispy_forms.layout import Layout, HTML, Div, Submit
# Put it variable to avoid writing it twice
buttons_layout = Layout(
Div(
HTML('<br>'),
FormActions(