M
M
mi1ord2017-12-03 13:01:24
Django
mi1ord, 2017-12-03 13:01:24

How to select from date ranges in Django?

Hi all!
I got into a dead end, but I think for the experienced it's like two fingers.
There is a concert model. And it has several dates with different durations. That is, it can go both one day and one week (range). Dates can be added/edited at any time. Implemented like this:
---------------------------------------- ------------------------

class Event(models.Model):
    name = models.CharField(max_length=200)
    # тут куча других полей
    period = models.ForeignKey(Period)

-------------------------------------------------- ---------------------
class Period(models.Model):
    begin = models.DateField(blank=True, null=True)
    end = models.DateField(blank=True, null=True)

-------------------------------------------------- ---------------------
Actually two questions: is there a more competent implementation ?
And how to filter the QuerySet if the user can enter a single date (what concerts are tomorrow, for example), as well as a range of dates (for example, what will be in five days)? In other words, you need to be able to select a date range from multiple date ranges.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question