Files
@ 7086387253d4
Branch filter:
Location: conntrackt/conntrackt/forms.py - annotation
7086387253d4
1.0 KiB
text/x-python
CONNT-4: Implemented custom ModelForm for Entity. Implemented create view for entities. Added tests for new functionality.
7086387253d4 7086387253d4 7086387253d4 7086387253d4 7086387253d4 7086387253d4 7086387253d4 7086387253d4 7086387253d4 7086387253d4 7086387253d4 7086387253d4 7086387253d4 7086387253d4 7086387253d4 7086387253d4 7086387253d4 7086387253d4 7086387253d4 7086387253d4 7086387253d4 7086387253d4 7086387253d4 7086387253d4 7086387253d4 7086387253d4 7086387253d4 7086387253d4 7086387253d4 7086387253d4 7086387253d4 7086387253d4 | # Django imports.
from django.forms import ModelForm
from django.forms.models import inlineformset_factory
# Application imports.
from .models import Entity, Interface
class EntityForm(ModelForm):
"""
Implements a custom model form for entities with some styling changes.
"""
class Meta:
model = Entity
def __init__(self, *args, **kwargs):
"""
Initialises the form instance. Sets-up some bootstrap CSS classes for
widgets.
"""
super(EntityForm, self).__init__(*args, **kwargs)
# Update the widgets to be wider, and set-up placeholder values for text
# boxes.
self.fields["name"].widget.attrs["class"] = "span6"
self.fields["name"].widget.attrs["placeholder"] = "Entity name"
self.fields["description"].widget.attrs["class"] = "span6"
self.fields["description"].widget.attrs["placeholder"] = "Description for new entity."
self.fields["project"].widget.attrs["class"] = "span6"
self.fields["location"].widget.attrs["class"] = "span6"
|