fixup rideshare a bit

This commit is contained in:
Thomas Steen Rasmussen 2019-07-11 20:48:14 +02:00
parent 881b0f4cf4
commit e4f6670c45
8 changed files with 87 additions and 13 deletions

View file

@ -5,5 +5,5 @@ from .models import Ride
@admin.register(Ride)
class RideModelAdmin(admin.ModelAdmin):
list_display = ("location", "when", "seats", "user")
list_display = ("camp", "user", "from_location", "to_location", "when", "seats")
list_filter = ("camp", "user")

View file

@ -0,0 +1,18 @@
# Generated by Django 2.1.7 on 2019-07-11 18:23
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('rideshare', '0002_auto_20180814_1942'),
]
operations = [
migrations.AddField(
model_name='ride',
name='has_car',
field=models.BooleanField(default=True, help_text='Leave checked if you are offering a ride, uncheck if you need a ride'),
),
]

View file

@ -0,0 +1,18 @@
# Generated by Django 2.1.7 on 2019-07-11 18:36
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('rideshare', '0003_ride_has_car'),
]
operations = [
migrations.RenameField(
model_name='ride',
old_name='location',
new_name='from_location',
),
]

View file

@ -0,0 +1,19 @@
# Generated by Django 2.1.7 on 2019-07-11 18:37
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('rideshare', '0004_auto_20190711_2036'),
]
operations = [
migrations.AddField(
model_name='ride',
name='to_location',
field=models.CharField(default='BornHack', max_length=100),
preserve_default=False,
),
]

View file

@ -7,8 +7,13 @@ from utils.models import UUIDModel, CampRelatedModel
class Ride(UUIDModel, CampRelatedModel):
camp = models.ForeignKey("camps.Camp", on_delete=models.PROTECT)
user = models.ForeignKey("auth.User", on_delete=models.PROTECT)
has_car = models.BooleanField(
default=True,
help_text="Leave checked if you are offering a ride, uncheck if you need a ride"
)
seats = models.PositiveIntegerField()
location = models.CharField(max_length=100)
from_location = models.CharField(max_length=100)
to_location = models.CharField(max_length=100)
when = models.DateTimeField(help_text="Format is YYYY-MM-DD HH:mm")
description = models.TextField()
@ -18,6 +23,6 @@ class Ride(UUIDModel, CampRelatedModel):
)
def __str__(self):
return "{} seats from {} at {} by {}".format(
self.seats, self.location, self.when, self.user
return "{} seats from {} to {} at {} by {}".format(
self.seats, self.from_location, self.to_location, self.when, self.user
)

View file

@ -16,7 +16,9 @@
<h4>
<strong>{{ object.seats }}</strong>
seats free, going from
<strong>{{ object.location }}</strong>
<strong>{{ object.from_location }}</strong>
to
<strong>{{ object.to_location }}</strong>
at
<strong>{{ object.when|date:"jS \o\f F \a\t H:i T" }}</strong>
</h4>

View file

@ -6,8 +6,8 @@
<h1>Ridesharing</h1>
</div>
<p>
On this page participants of {{ camp.title }} can communicate about ridesharing to and from the festival.
<p class="lead">
On this page participants of {{ camp.title }} can communicate about ridesharing to and from the festival. Press "Details" to send a message to the author of the entry.
</p>
<a class="btn btn-success pull-right" href="{% url 'rideshare:create' camp_slug=camp.slug %}">
@ -21,20 +21,32 @@ On this page participants of {{ camp.title }} can communicate about ridesharing
<table class="table table-condensed table-striped">
<thead>
<th>
When
Type
<th>
Location
Leaving When
<th>
Seats
From Location
<th>
To Location
<th>
Seats Free/Needed
<th>
<tbody>
{% for ride in ride_list %}
<tr>
<td>
{% if ride.has_car %}
<i class="fas fa-car"></i> Has car
{% else %}
<i class="fas fa-thumbs-up"></i> Needs ride
{% endif %}
<td>
{{ ride.when|date:"c" }}
<td>
{{ ride.location }}
{{ ride.from_location }}
<td>
{{ ride.to_location }}
<td>
{{ ride.seats }}
<td>

View file

@ -63,7 +63,7 @@ class RideDetail(LoginRequiredMixin, CampViewMixin, DetailView):
class RideCreate(LoginRequiredMixin, CampViewMixin, CreateView):
model = Ride
fields = ["location", "when", "seats", "description"]
fields = ["has_car", "from_location", "to_location", "when", "seats", "description"]
def form_valid(self, form, **kwargs):
ride = form.save(commit=False)
@ -81,7 +81,7 @@ class IsRideOwnerMixin(UserPassesTestMixin):
class RideUpdate(LoginRequiredMixin, CampViewMixin, IsRideOwnerMixin, UpdateView):
model = Ride
fields = ["location", "when", "seats", "description"]
fields = ["has_car", "from_location", "to_location", "when", "seats", "description"]
class RideDelete(LoginRequiredMixin, CampViewMixin, IsRideOwnerMixin, DeleteView):