friendsmap/map/models.py

37 lines
911 B
Python
Raw Normal View History

2019-03-02 12:04:27 +01:00
from django.contrib.auth.models import AbstractUser
from django.db import models
2019-03-02 12:47:44 +01:00
from map.fields import CoordinateField
class BaseModel(models.Model):
class Meta:
abstract = True
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
2019-03-02 12:04:27 +01:00
class Friend(AbstractUser):
pass
2019-03-02 12:47:44 +01:00
class FriendLocation(BaseModel):
latitude = CoordinateField()
longitude = CoordinateField()
start_date = models.DateField('from', blank=True, null=True)
end_date = models.DateField('until', blank=True, null=True)
friend = models.ForeignKey(Friend, on_delete=models.CASCADE)
@property
def latitude_str(self):
return str(self.latitude)
@property
def longitude_str(self):
return str(self.longitude)
def __str__(self):
return f'{self.friend.get_full_name()} from {self.start_date} to {self.end_date}'