D
D
DennyD3142016-12-19 18:44:07
Django
DennyD314, 2016-12-19 18:44:07

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='Номер теллефона

I display the form on the page:
class RegistrationToEventForm(ModelForm):
    class Meta:
        model = PeopleReg
        fields = ['event', 'name', 'email', 'phone']

<form method="POST">
    {% csrf_token %}
    {{ form }}
    <input type="submit" value="Submit" />
</form>

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
How do I display only objects with a date greater than the current one (timezone.now()) ? When generating the schedule, I filtered qs by date.
To make such a thing that when you select a value from the first drop-down list, only the values ​​associated with the selected value will remain in the second drop-down list, you need to know js , use ajax?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
X
Xander017, 2016-12-19
@DennyD314

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

For example:
from datetime import date

tod = date.today()
print(tod)
print(tod.strftime("%d.%m.%Y %H:%M"))

Result:
>>> 2016-12-19
>>> 19.12.2016 00:00

Documentation

A
Andrey K, 2016-12-20
@mututunus

https://docs.djangoproject.com/en/1.10/ref/setting...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question