'Getting queryset with direct results

Is there any way to actually get queryset by direct values of params? I'm scraping data from api and sometimes there are 3 options. Single record can have full date which is year-month-day, another one could have only year-month and another could have only year. If there is certain date in my database, then i want to get it and add to the new object, but if there is not, then i want to create it. The problem is that, when i'm getting value of let's say year 2017, then i can get values of 2017, 2017-month, and 2017-month-day. Is there any way to search in database so it can act that if param have no value, then it's null?

My model here:

class Date(models.Model):
    year = models.PositiveIntegerField()
    month = models.PositiveIntegerField(blank=True, null=True, validators=[
            MaxValueValidator(12),
            MinValueValidator(1)])
    day = models.PositiveIntegerField(blank=True, null=True, validators=[
            MaxValueValidator(31),
            MinValueValidator(1)])


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source