class Follow(models.Model): follower = models.ForeignKey(CustomUser, related_name='follower', on_delete=models.CASCADE, default=None) followee = models.ForeignKey(CustomUser, related_name='followee', on_delete=models.CASCADE, default=None) time = models.DateTimeField(_('time'), default=timezone.now) def __unicode__(self): return str(self.follower) + ' follows ' + str(self.followee) def __str__(self): return str(self.follower) + ' follows ' + str(self.followee) def is_follows(self, user_1, user_2): foll = Follow.objects.filter(user=user_1, follower=user_2) if foll.exists(): return True else: return False def get_absolute_url(self): return "/app/profile/%s" % self.follower.username
class Message(models.Model): sender = models.ForeignKey(CustomUser, related_name='sender', on_delete=models.CASCADE) recipient = models.ForeignKey(CustomUser, related_name='recipient', on_delete=models.CASCADE) subject = models.CharField(default='(No Subject)', max_length=256) message = models.TextField(blank=False) date = models.DateTimeField(_('time sent'), default=timezone.now) read = models.BooleanField(_('read'), default=False) deleted = models.BooleanField(_('deleted'), default=False) def __str__(self): return self.sender.username + ' to ' + self.recipient.username + ' - ' + self.message[ 0:20] + '...' def url(self): return '/app/user/dashboard/messages/%d/read/' % self.pk def send(self, user, recipient, subject, message): message = Message() message.sender = user message.recipient = recipient message.subject = subject message.message = message message.save()
class VehicleSharing(models.Model): start = models.CharField( _('starting point'), max_length=256, blank=False, ) dest = models.CharField(_('destination'), max_length=256, blank=False) cost = models.IntegerField(_('cost'), blank=False) date = models.DateField(_('date'), default=timezone.now) start_time = models.TimeField(_('start time'), max_length=256, blank=False) arrival_time = models.TimeField(_('estimated arrivak'), max_length=256, blank=False) no_pass = models.IntegerField(_('no of passengers'), blank=False) details = models.TextField(_('ride details'), blank=False) choices = (('Male', 'Male'), ('Female', 'Female'), ('Both', 'Both')) sex = models.CharField(_('gender preference'), max_length=30, blank=False, choices=choices) user = models.ForeignKey(CustomUser, on_delete=models.CASCADE) vehicle = models.ForeignKey(Vehicle, on_delete=models.CASCADE) ended = models.BooleanField(_('sharing ended'), default=False) def __str__(self): return self.start + " to " + self.dest def get_user(self): return self.user def get_absolute_url(self): return "/app/sharing/%d/view" % self.pk
class Vehicle(models.Model): year = models.IntegerField(_('year of purchase'), blank=False) make = models.CharField(_('vehicle make'), max_length=254, blank=False) plate = models.CharField(_('liscenced plate number'), max_length=10, blank=False) model = models.CharField(_('vehicle model'), max_length=254, blank=False) seats = models.IntegerField(_('no of seats'), blank=False) user_choices = (('private', 'private'), ('hired', 'hired')) type = models.CharField(_('vehicle type'), max_length=30, blank=False, choices=user_choices) user_choices = (('Car', 'Car'), ('Bus', 'Bus'), ('Coaster', 'Coaster'), ('Truck', 'Truck')) category = models.CharField(_('vehicle category'), max_length=30, blank=False, choices=user_choices) user = models.ForeignKey(CustomUser, on_delete=models.CASCADE) def get_absolute_url(self): return "/app/ride/%d/view" % self.pk def __str__(self): return self.make + " " + self.model + " belonging to " + self.user.username
class Request(models.Model): pick = models.CharField( _('pick up point'), max_length=256, blank=False, ) dest = models.CharField(_('destination'), max_length=256, blank=False) reg_date = models.DateTimeField(_('registration date'), default=timezone.now) user = models.ForeignKey(CustomUser, on_delete=models.CASCADE) bearable = models.IntegerField(_('bearable cost'), blank=False) status = models.CharField(_('status'), max_length=256, blank=False, default='pending') ride = models.ForeignKey(VehicleSharing, on_delete=models.CASCADE) def __str__(self): return "request from " + self.user.get_full_name( ) + " on " + self.reg_date.isoformat(' ')[0:16] def get_absolute_url(self): return "/app/request/%d/view" % self.pk