bornhack-website/src/rideshare/models.py

42 lines
1.5 KiB
Python
Raw Normal View History

2018-08-08 20:18:39 +00:00
from django.db import models
from django.urls import reverse
from utils.models import CampRelatedModel, UUIDModel
2018-08-08 20:18:39 +00:00
class Ride(UUIDModel, CampRelatedModel):
2019-06-16 12:32:24 +00:00
camp = models.ForeignKey("camps.Camp", on_delete=models.PROTECT)
user = models.ForeignKey("auth.User", on_delete=models.PROTECT)
2020-02-07 17:46:34 +00:00
author = models.CharField(
max_length=100, help_text="Let people know who posted this", default="Anonymous"
)
2019-07-11 18:48:14 +00:00
has_car = models.BooleanField(
default=True,
2020-02-07 17:46:34 +00:00
help_text="Leave checked if you are offering a ride, uncheck if you need a ride.",
)
seats = models.PositiveIntegerField(
help_text="How many seats are you offering/how many seats do you need?"
)
from_location = models.CharField(
max_length=100, help_text="Where does this ride begin?"
)
to_location = models.CharField(
max_length=100, help_text="What is the destination of this ride?"
)
when = models.DateTimeField(
help_text="When does this ride leave? Format is YYYY-MM-DD HH:mm"
)
description = models.TextField(
help_text="Include any details you want, like luggage space/requirements, contact info and so on."
2019-07-11 18:48:14 +00:00
)
2018-08-08 20:18:39 +00:00
def get_absolute_url(self):
return reverse(
2019-06-16 12:32:24 +00:00
"rideshare:detail", kwargs={"pk": self.pk, "camp_slug": self.camp.slug}
2018-08-08 20:18:39 +00:00
)
2018-08-10 16:46:54 +00:00
def __str__(self):
2019-07-11 18:48:14 +00:00
return "{} seats from {} to {} at {} by {}".format(
self.seats, self.from_location, self.to_location, self.when, self.user
2018-08-10 16:46:54 +00:00
)