This is my model:
class Event(models.Model):
title = models.CharField(max_length = 255)
club = models.CharField(max_length=70)
event_image = models.ImageField(upload_to="event_images", default='aqsa_copy.jpeg', blank=True)
date = models.DateTimeField(null = True)
location = models.CharField(max_length=30)
first_name = models.CharField(max_length=15)
This is how it displayed in the admin:
I want to make it like this at the template, and be able to pick a date and time.
But what I got for now is that:
Please help me if you can?
1
You can archive those things using widgets
functionality of django model form
form.py
class EventForm(forms.ModelForm):
class Meta:
model = Event
fields = ['title', 'club', 'date', 'location', 'first_name']
widgets = {
'date': forms.DateInput(attrs={'type': 'datetime-local'}),
}
# Html code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
{{form}}
</body>
</html>
Final Output