Skip to main content

Posts

Showing posts from June, 2020

Date and Time picker

I'm still learning how to use all these widges in Django. The first one I tried out was the date and time widgets for date and time fields. Turns out it was fairly simple to do so. I didn't need to use any Javascript at all. It took me awhile to understand that widgets are basically a representation of HTML input elements. So the attributes are determined by the HTML inputs. Initially I kept wondering where these attributes came from because they were not spelled out in the Django documentation. Silly me :P models.py Date = models.DateField( default = None ) Time = models.TimeField( default = "12:00" ) forms.py class MyForm(ModelForm): class Meta: model = MyModel widgets = { 'Date' : forms.DateInput( attrs ={ 'type' : 'date' }) , 'Time' : forms.TimeInput( attrs ={ 'type' : 'time' }) , }

Processing user input before saving

Post bootcamp, I didn't even think I could get back into programming. I wasn't confident getting a real programming job, but thankfully, a position opened up at my school for an instructor. I spend a lot of time nagging students about completing their work, but I also get to see their submissions and help them out when they're stuck. This has given me the opportunity to play around with their code without the stress of deadlines. Especially now that I'm handling the Python project. I feel extremely grateful for this opportunity, but I am well aware that I have a long way to go.  A student was looking into using the timefield for his model and wanted to calculate the difference between the 2 user inputs and save it. He later changed his mind about it, but it gave me the opportunity to look into how this can be done.  I took a long time to figure this out, but I'm pleased I did :)  form = MyForm(request.POST or None ) if form.is_valid(): updatedForm = form