class ClockPunch(models.Model): employee = models.ForeignKey(settings.AUTH_USER_MODEL) date = models.DateField(auto_now_add=True) punched_in = models.BooleanField(default=False) punch_in_time = models.DateTimeField(blank=True, null=True) punch_in_ip = models.GenericIPAddressField(blank=True, null=True) punched_out = models.BooleanField(default=False) punch_out_time = models.DateTimeField(blank=True, null=True) punch_out_ip = models.GenericIPAddressField(blank=True, null=True) hours_for_the_day = models.DecimalField(max_digits=4, decimal_places=2, default="0.00", blank=True, null=True)
class Meta: ordering = ['date', ]
def __str__(self): return self.pk
class ClockPunchInView(LoginRequiredMixin, CreateView): context_object_name = "clock_punch" fields = ['punch_in_time', 'punched_in',] model = ClockPunch template_name = 'pages/layout.html' success_url = '/'
def form_valid(self, form): object = form.save(commit=False) object.employee = self.request.user object.punch_in_time = timezone.now() object.punched_in = True object.save() return super(ClockPunchInView, self).form_valid(form)
class ClockPunchOutView(LoginRequiredMixin, CreateView): context_object_name = "clock_punch" model = ClockPunch fields = ['punch_out_time', 'punched_out',] #form_class = PunchOutForm template_name = 'pages/layout.html' success_url = '/'
def form_valid(self, form): object = form.save(commit=False) last_entry = ClockPunch.objects.filter(employee=self.request.user).order_by("-punch_in_time").first()
if last_entry.punched_in: object.employee = self.request.user object.punch_out_time = timezone.now() object.punched_out = True object.save() return super(ClockPunchOutView, self).form_valid(form) else: return redirect('/')
<form method='POST' action='{% url 'administration:clock_in' %}'> {% csrf_token %} <input type="submit" style="margin-right:6px;" type="button" class="btn btn-success" value="Clock-in"></button> </form> <form method='POST' action='{% url 'administration:clock_out' %}'> {% csrf_token %} <input type="submit" style="margin-right:6px;" type="button" class="btn btn-danger" value="Clock-out"></button> </form>
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2da8a91c-804c-40b4-bfc4-a4da911b1070%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.