0

Is it possible to somehow get an absolute url in Django (respectively domain name)? My site send's emails to admin and I want to put a link into this email to redirect him to mysite/admin/some-tab.

I've read answers on similar question - HERE, but I can't use request because it's in python script (notifications.py), not in template or views.py.

class AdminNotifications():
    @staticmethod
    def new_reservation(reservation):
        pass

    @staticmethod
    def new_pair(reservation1, reservation2):
        if reservation2.destination_to.is_airport:
            reservation1 , reservation2 = reservation2 , reservation1

        subject = u'Nový pár'

        message = u'Nový možný pár \n\nRezervácia 1: \n' \
                  u'ID rezervácie: {}\n' \
                  u'Zákazník: {}\n' \
                  u'Z: {}\n' \
                  u'Do: {}\n' \
                  u'Číslo letu: {}\n' \
                  u'Dátum odletu: {}\n' \
                  u'Čas odletu {}'.format(
            reservation1.id,
            reservation1.customer,
            reservation1.destination_from,
            reservation1.destination_to,
            reservation1.flight_number,
            reservation1.date_departure,
            reservation1.time_departure,

        ) + u'\n\nRezervácia 2: \n' \
                  u'ID rezervácie: {}\n' \
                  u'Zákazník: {}\n' \
                  u'Z: {}\n' \
                  u'Do: {}\n' \
                  u'Číslo letu: {}\n' \
                  u'Dátum príletu: {}\n' \
                  u'Čas príletu: {}'.format(
            reservation2.id,
            reservation2.customer,
            reservation2.destination_from,
            reservation2.destination_to,
            reservation2.flight_number,
            reservation2.date_arrival,
            reservation2.time_arrival,)+ \
                  u'\n\n\n\nRezervácie môžte upraviť tu: >> HERE I WANT TO PUT HREF TO MYSITE/ADMIN/SOME-TAB
        send_message_to_admin(subject,message)
Community
  • 1
  • 1
Milano
  • 18,048
  • 37
  • 153
  • 353
  • 1
    You are getting `reservation1` and `reservation2` from somewhere, can't you get `request` or `URL` from the same place? – Muhammad Tahir Aug 05 '16 at 10:59
  • I'm not sure since it's from Reservation model save() method, but I'm using overwritten save method for ReservationCreationModelForm to save it. – Milano Aug 05 '16 at 11:51
  • 1
    You need to pass the request or `request.build_absolute_uri()` from the view to the model then, as http://stackoverflow.com/a/7366386/1688590 pass `request.user`. – xbello Aug 05 '16 at 12:56

0 Answers0