I want to accept users birthday and have a page which shows everyone's birthday ignoring which year they were born in Heres my models.py for CustomUser:
from datetime import datetime, date
from django.contrib.auth.models import AbstractUser
from django.db import models
class CustomUser(AbstractUser):
# First/last name is not a global-friendly pattern
name = models.CharField(blank=True, max_length=255)
birth_date = models.DateField(("Birth Date"), default=date.today)
def __str__(self):
return self.email
Here is my views.py logic:
def birthdaylist(request):
if(request.user.is_authenticated):
users=CustomUser.objects.order_by('birth_date')[:]
# ignore the line below
# users= CustomUser.objects.extra(select={'birthmonth':'birth_date'},order_by=['birthmonth'])
context={
'users':users
}
return render(request,'dashboard/birthdaylist.html',context=context)
else:
return redirect('login')
Here is my forms.py:
import datetime
from bootstrap_datepicker_plus import DatePickerInput
from django import forms
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from .models import CustomUser
class CustomUserCreationForm(UserCreationForm):
class Meta(UserCreationForm.Meta):
model = CustomUser
now = datetime.datetime.now()
fields = ('username', 'email', 'gender', 'security_question', 'answer', 'birth_date', 'resume')
widgets={
'birth_date' :DatePickerInput(
options={
'maxDate':str(datetime.datetime.now()),
#this needs width positioning
}
)
}
I am using bootstrap datepicker plus widget to pick the date. Can someone help me on how do I get the desired result in my views .py? I feel something needs to be added in my order.py if u need me to add anything then comment. PS: I am using Django 2.0.6 version
Try
How about this one?