amitgaru2 / nepali-datetime

Python's core datetime inspired Bikram Sambat (BS date) & Nepal Time (NPT) package🇳🇵
https://pypi.org/project/nepali-datetime/
MIT License
61 stars 30 forks source link

Neep Help #4

Closed saileshkush95 closed 4 years ago

saileshkush95 commented 4 years ago

Sorry for this question, I know this is not a good platform for asking question. Actually I want to build a calendar using django same as below. image.

I've no idea, how to achieve this one. So can you please share some idea, or guide , that can help me to achieve this. and the last question is how can i use this package in my project. Please give me some idea, I wan't to learn some things in this lock down period.

I'm using django, and python default HTML Calendar modules and here is my progress. Screenshot_20200504_222010

amitgaru2 commented 4 years ago

There is no straight forward solution for this problem from this library. But there is a way around how you can construct calendar on your own by fetching data from NepaliDate.

What you can do on your views is, for eg you want the calendar for Ashar 2077,

  1. First of all create a instance of NepaliDate for first day of Ashar 2077 by
    
    from nepali_date import NepaliDate

first_day_month = NepaliDate(2077, 3, 1)


2. Next find total days in that month. You can do that by
```python
total_days_month = NepaliDate.calendar_data[2077][3-1]
  1. Finally find from which day the month starts from (Sun/Mon/Tue/...)
    first_day_month.weekday

So from your views you can pass like first day in the month and total days in the month, like for this case the first day is Mon and total days in the month is 31 to your calendar template. So based on these two values you can apply some looping logic and display the calendar.

I hope this helps. Thank you.