I have the below code if self.request.user.is_authenticated() and self.request.user. userlocation What I don't understand is why I am getting this User has no userlocation error. I have a if statement if he condition is not met should it not just go down and show the context
class Homepage(TemplateView):
template_name = 'home.html'
def get_context_data(self, **kwargs):
context = super(Homepage, self).get_context_data(**kwargs)
context['event_list'] = Event.objects.all()
if self.request.user.is_authenticated() and self.request.user.userlocation:
print("The code reached here ")
return context
below are the models.py
class UserLocation(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
lat = models.FloatField(blank=True, null=True)
lon = models.FloatField(blank=True, null=True)
point = models.PointField(srid=4326, default='SRID=4326;POINT(0.0 0.0)')
objects = models.GeoManager()
