from __future__ import unicode_literals

from django.db import models
from django.contrib.auth.models import User, Group
from datetime import datetime


class Car(models.Model):
    name = models.CharField(max_length=255)
    description = models.CharField(max_length=255)
    group = models.ForeignKey(Group)

    def __str__(self):
        return "%s" % self.name

    def __unicode__(self):
        return u"%s" % self.name

class Expense(models.Model):
    CURRENCY = (
        ('EUR', 'EUR'),
        ('USD', 'USD'),
        ('GBP', 'GBP'),
        ('other', 'other'),
    )

    user = models.ForeignKey(User)
    car = models.ForeignKey(Car)
    date = models.DateTimeField(default=datetime.now)
    #paid_by = models.ForeignKey(User)
    price = models.DecimalField(max_digits=5, decimal_places=2)
    price_per_unit = models.DecimalField(max_digits=5, decimal_places=4)
    currency = models.CharField(max_length=10, choices=CURRENCY, default='EUR')
    volume = models.IntegerField(default=40)
    mileage = models.IntegerField()
    range = models.IntegerField(default=900)
    consumption = models.DecimalField(max_digits=5, decimal_places=2, default=5.8)
    date_created = models.DateTimeField(auto_now_add=True)
    date_modified = models.DateTimeField(auto_now=True)

    def __str__(self):
        return "%s - %s %s" % (self.car, self.user, self.date)

    def __unicode__(self):
        return u"%s - %s %s" % (self.car, self.user, self.date)
