Commits

Alex Padalka committed d510d53

- fix inheritance

  • Participants
  • Parent commits b68b2fb

Comments (0)

Files changed (2)

avblty_app/models.py

 from django.utils.dates import WEEKDAYS
 
 
+class BaseAvailability(models.Model):
+    weekday = models.PositiveSmallIntegerField(choices=WEEKDAYS.items())
+    start_time = models.TimeField()
+    end_time = models.TimeField()
+    user = models.ForeignKey(User, related_name='%(app_label)s_%(class)s_related')
+
+    class Meta:
+        abstract = True
+
+
 class UserAvailableModelManager(models.Manager):
     def get_query_set(self):
         return UserAvailableQuerySet(self.model)
         return query.exclude(exclude_id) if exclude_id else query
 
 
-class UserAvailable(models.Model):
-    weekday = models.PositiveSmallIntegerField(choices=WEEKDAYS.items())
-    start_time = models.TimeField()
-    end_time = models.TimeField()
-    user = models.ForeignKey(User)
-
+class UserAvailable(BaseAvailability):
     objects = UserAvailableModelManager()
 
     def merge_availability_intersection(self, items):
         ordering = ['user', 'weekday', 'start_time']
 
 
-class Event(UserAvailable):
-    requested_by = models.ForeignKey(User)
+class Event(BaseAvailability):
+    requested_by = models.ForeignKey(User, related_name='requested_by_user')
 
 

avblty_app/views.py

 
     def get_form_kwargs(self):
         kwargs = super(CreateEventView, self).get_form_kwargs()
-        kwargs.update({'users_queryset': User.objects.all()}) # exclude(pk=self.request.user.pk)
+        kwargs.update({'users_queryset': User.objects.exclude(pk=self.request.user.pk)})
         return kwargs
 
     def get(self, request, *args, **kwargs):