Answer the question
In order to leave comments, you need to log in
How to set the date format?
Hello!
I have 3 models:
class Excursion (models.Model):
name = models.CharField(max_length=50, verbose_name='Название экскурсии')
description = RichTextUploadingField(verbose_name='Описание')
img = models.ImageField(upload_to='images', blank=True, verbose_name='Изборажение (не обязательно)')
slug = models.SlugField(unique=True, verbose_name='Адрес')
class Meta:
verbose_name_plural = 'Список экскурсий'
def __str__(self):
return self.name
class Event(models.Model):
excursion = models.ForeignKey(Excursion, on_delete=models.CASCADE)
starting = models.DateTimeField(verbose_name='Дата мероприятия')
img = models.ImageField(upload_to='images', verbose_name='Изображение', blank=True)
name = models.CharField(max_length=50, blank=True, editable=False)
description = RichTextUploadingField(blank=True, editable=False)
def save(self, *args, **kwargs):
self.name = self.excursion.name
self.description = self.excursion.description
super(Event, self).save(*args, **kwargs)
class Meta:
verbose_name_plural = 'Мероприятия'
def __str__(self):
return self.excursion.name + ' - ' + str(self.starting)
class PeopleReg(models.Model):
event = models.ForeignKey(Event, on_delete=models.CASCADE)
name = models.CharField(max_length=25, verbose_name='Имя')
email = models.EmailField(verbose_name='почта')
phone = models.CharField(max_length=10, verbose_name='Номер теллефона
class RegistrationToEventForm(ModelForm):
class Meta:
model = PeopleReg
fields = ['event', 'name', 'email', 'phone']
<form method="POST">
{% csrf_token %}
{{ form }}
<input type="submit" value="Submit" />
</form>
Answer the question
In order to leave comments, you need to log in
The date is displayed in some strange format. For example, 2016-10-10 09:00:00 + 00:00
I would like to see a format like 09/10/2016 23:16
from datetime import date
tod = date.today()
print(tod)
print(tod.strftime("%d.%m.%Y %H:%M"))
>>> 2016-12-19
>>> 19.12.2016 00:00
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question