class MainYear(models.Model):
year = models.CharField(max_length=4,blank=True,null=True,default=get_current_year())
def __str__(self):
return str(self.year)
@property
def get_all_month(self):
return self.MainMonth.all()
def get_absolute_url(self):
return reverse("agenda:ajax_month", kwargs={"pk": self.id})
class MainMonth(models.Model):
main_year = models.ForeignKey(MainYear,on_delete=models.CASCADE,blank=True,null=True,related_name="MainYear")
month = models.PositiveSmallIntegerField (validators=[MaxValueValidator(12)],default=1,blank=True,null=True)
day_count = models.PositiveSmallIntegerField (validators=[MaxValueValidator(31)],blank=True,null=True)
def __str__(self):
return str(self.month)
@property
def get_day_count(self):
# year = self.__main_year.year()
year = self.objects.all().filter(main_year__MainYear_year='MainYear_year')
for y in year:
yea_to_days = self.year # You already have it
days_count = monthrange(int(yea_to_days),int(self.month))[1]
self.day_count = days_count
return self.day_count
My problem is i want if i select year like 2024 it should be in February 29 days how to make it
i will be save it auto by using save method
django python year month days