# Path: py_arduino_web/dj/models.py
# class Pin(models.Model):
#     pin = models.PositiveIntegerField()
#     digital = models.BooleanField()
#     label = models.CharField(max_length=64,
#         help_text="Descriptive text for a pin. Ej: 'Status Led'")
#     pin_id = models.CharField(max_length=64, unique=True, null=True, blank=True,
#         help_text="Unique identifier for internal use of a pin. Ej: 'status-led'")
#     enabled_in_web = models.BooleanField(default=True)
# 
#     def save(self, *args, **kwargs):
#         if self.pin_id is not None and len(self.pin_id.strip()) == 0:
#             self.pin_id = None
#         super(Pin, self).save(*args, **kwargs) # Call the "real" save() method.
# 
#     def __unicode__(self):
#         if self.digital:
#             ret = u"Digital pin #{0}".format(self.pin)
#         else:
#             ret = u"Analog pin #{0}".format(self.pin)
#         if self.label:
#             ret = u"{0} ('{1}')".format(ret, self.label)
#         return ret
# 
#     class Meta:
#         unique_together = (('pin', 'digital',),)


from django.contrib import admin
from django import forms
from py_arduino_web.dj.models import Pin



class PinFormAdmin(forms.ModelForm):

    class Meta:
        model = Pin

    def clean_pin_idpin_id(self):
        if not self.cleaned_data["pin_id"].strip():
            return None
        return self.cleaned_data["pin_id"]


class PinAdmin(admin.ModelAdmin):
    list_display = ('label', 'pin', 'pin_type', 'pin_id', 'enabled_in_web')
    ordering = ('digital', 'pin',)
    readonly_fields = ('pin', 'pin_type')
    fields = ('pin', 'pin_type', 'label', 'pin_id', 'enabled_in_web')

    def pin_type(self, obj):
        if obj.digital:
            return u"Digital"
        else:
            return u"Analog"

    pin_type.short_description = 'Pin Type'


# Path: py_arduino_web/dj/models.py
# class Pin(models.Model):
#     pin = models.PositiveIntegerField()
#     digital = models.BooleanField()
#     label = models.CharField(max_length=64,
#         help_text="Descriptive text for a pin. Ej: 'Status Led'")
#     pin_id = models.CharField(max_length=64, unique=True, null=True, blank=True,
#         help_text="Unique identifier for internal use of a pin. Ej: 'status-led'")
#     enabled_in_web = models.BooleanField(default=True)
# 
#     def save(self, *args, **kwargs):
#         if self.pin_id is not None and len(self.pin_id.strip()) == 0:
#             self.pin_id = None
#         super(Pin, self).save(*args, **kwargs) # Call the "real" save() method.
# 
#     def __unicode__(self):
#         if self.digital:
#             ret = u"Digital pin #{0}".format(self.pin)
#         else:
#             ret = u"Analog pin #{0}".format(self.pin)
#         if self.label:
#             ret = u"{0} ('{1}')".format(ret, self.label)
#         return ret
# 
#     class Meta:
#         unique_together = (('pin', 'digital',),)


# Path: py_arduino_web/dj/admin.py
from django.contrib import admin
from django import forms
from py_arduino_web.dj.models import Pin




class PinFormAdmin(forms.ModelForm):

    class Meta:
        model = Pin

    def clean_pin_idpin_id(self):
        if not self.cleaned_data["pin_id"].strip():
            return None
        return self.cleaned_data["pin_id"]


class PinAdmin(admin.ModelAdmin):
    list_display = ('label', 'pin', 'pin_type', 'pin_id', 'enabled_in_web')
    ordering = ('digital', 'pin',)
    readonly_fields = ('pin', 'pin_type')
    fields = ('pin', 'pin_type', 'label', 'pin_id', 'enabled_in_web')

    def pin_type(self, obj):
        if obj.digital:
            return u"Digital"
        else:
            return u"Analog"

    pin_type.short_description = 'Pin Type'


admin.site.register(Pin, PinAdmin)