0

I have a model like this

class Orders(models.Model):
     company = models.ForeignKey(Company, on_delete=models.CASCADE)

The logic is the companies to send offers to get the specific travel. When you send an offer you will not have access to that travel anymore untill the base company accept or reject your offer.

So when the specific company logged in I want to show them if they sent an offer or not. The company name is saved in the user that is logged in.

What I tried to do is this

class Order(models.Model):
    @property
    def has_sent_offer(self):
         Offer.objects.filter(order=self.pk, company=request.user.company)

But in the models.py I don't have access to request.user

maca
  • 480
  • 3
  • 12
  • 1
    Django does not have such a feature. You must pass in `request` (or user) explicitly as an argument to the method. That means that the method can only be called from a context with access to request, like a view function or in middleware. Also it cannot be a property, since request must be a required argument. – Håken Lid Dec 28 '21 at 15:04
  • 1
    I have already asked this question here check: https://stackoverflow.com/questions/52219902/how-to-safely-access-request-object-in-django-models – Ahtisham Dec 28 '21 at 15:18
  • 1
    Does this answer your question? [How to safely access request object in Django models](https://stackoverflow.com/questions/52219902/how-to-safely-access-request-object-in-django-models) – Ahtisham Dec 28 '21 at 15:23

0 Answers0