from __future__ import unicode_literals

from django.db import models
from django.urls import reverse
from django.conf import settings
from django.utils.six import python_2_unicode_compatible


@python_2_unicode_compatible
class Sensors(models.Model):
    date = models.DateTimeField(unique=True)
    t_amb = models.DecimalField(max_digits=4, decimal_places=1)
    t_obj = models.DecimalField(max_digits=4, decimal_places=1)
    rh = models.PositiveIntegerField()
    hpa = models.DecimalField(max_digits=5, decimal_places=1)
    lux = models.PositiveIntegerField()
    wind = models.DecimalField(max_digits=4, decimal_places=2)
    water = models.DecimalField(max_digits=4, decimal_places=2)

    def get_absolute_url(self):
        return reverse("sensors:detail", args=(self.id,))

    def __str__(self):
        return "[@{}] t_amb: {}, t_obj:{}, rh:{}, hpa:{}, lux:{}, water:{}, wind:{}".format(
            self.date,
            self.t_amb,
            self.t_obj,
            self.rh,
            self.hpa,
            self.lux,
            self.water,
            self.wind,
        )


@python_2_unicode_compatible
class Actions(models.Model):
    date = models.DateTimeField(unique=True)
    mist = models.BooleanField(default=False)
    fan = models.BooleanField(default=False)
    heat = models.BooleanField(default=False)
    water = models.BooleanField(default=False)
    light = models.BooleanField(default=False)
    reason = models.TextField(default='')

    def __str__(self):
        return "[@{}] mist:{} fan:{} water:{} light:{} heat:{} reason:{}".format(
            self.date,
            self.mist,
            self.fan,
            self.water,
            self.light,
            self.heat,
            self.reason,
        )

    def equals(self, action):
        return self.mist == action.mist and self.water == action.water and self.fan == action.fan and self.light == action.light and self.heat == action.heat


@@ -186,16 +186,45 @@
 atible%0A%0A
+from orchid_app import utils%0A
 %0A@python
@@ -1117,16 +1117,124 @@
      )%0A%0A
+    def get_all_fields(self, exclude=('id', 'date')):%0A        return get_all_fields(self, exclude=exclude)%0A%0A
 %0A@python
@@ -1913,16 +1913,16 @@
 ction):%0A
-
         
@@ -2072,8 +2072,776 @@
 n.heat%0A%0A
+    def get_all_fields(self, exclude=('id', 'date', 'reason')):%0A        return get_all_fields(self, exclude=exclude)%0A%0A%0Adef get_all_fields(obj, exclude=%5B%5D):%0A    '''Returns a Dict of all field names and values.%0A    Exclude non-meaningful fields.'''%0A%0A    fields = utils.Dict()%0A    # Correct user input for exclude parameter%0A    if not exclude:%0A        exclude = %5B%5D%0A%0A    for f in obj._meta.fields:%0A        fname = f.name%0A        # get value of the field%0A        try:%0A            value = getattr(obj, fname)%0A        except AttributeError:  # maybe use: obj.DoesNotExist ?%0A            value = None%0A%0A        # only display fields with values and skip some fields entirely%0A        if f.editable and fname not in exclude:%0A            fields%5Bfname%5D = value%0A%0A    return fields%0A%0A%0A

Add get_all_fields() to models.