Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/guests error #1

Open
nature-li opened this issue Aug 19, 2021 · 1 comment
Open

/guests error #1

nature-li opened this issue Aug 19, 2021 · 1 comment

Comments

@nature-li
Copy link

NameError at /guests/

name 'Booking' is not defined
Request Method: GET
http://127.0.0.1:8000/guests/
3.1.4
NameError
name 'Booking' is not defined
/code/github/Django---Hotel-Management-System/HMS/accounts/models.py, line 15, in numOfBooking
code/github/venv/bin/python
3.8.10
['/code/github/Django---Hotel-Management-System/HMS', '/usr/lib/python38.zip', '/usr/lib/python3.8', '/usr/lib/python3.8/lib-dynload', '/code/github/venv/lib/python3.8/site-packages']
Thu, 19 Aug 2021 09:44:20 +0000
@JithinW
Copy link

JithinW commented Oct 22, 2021

I have fixed this issue, It is showing "Booking is not defined" because the Booking model is defined inside room-->models.py and the Booking model methods are written inside account-->models.py. So you have to do is copying those methods and just put it below the Booking model inside room-->models.py. follow these steps:

Go to accounts directory, open models.py. There you can see model named "Guest", there you have to cut these lines which is selected.

image

Then you have to go to room directory and open models.py. There you will see a Booking model class. You have to paste those code here as shown in this figure below

image

or paste this

def numOfBooking(self):
    return Booking.objects.filter(guest=self).count()

def numOfDays(self):
    totalDay = 0
    bookings = Booking.objects.filter(guest=self)
    for b in bookings:
        day = b.endDate - b.startDate
        totalDay += int(day.days)

    return totalDay

def numOfLastBookingDays(self):
    try:
        return int((Booking.objects.filter(guest=self).last().endDate - Booking.objects.filter(
            guest=self).last().startDate).days)
    except:
        return 0

def currentRoom(self):
    booking = Booking.objects.filter(guest=self).last()
    return booking.roomNumber

Now it's fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants