Try-Django-1.11 icon indicating copy to clipboard operation
Try-Django-1.11 copied to clipboard

print(user) always prints 'None' in the terminal

Open apoorvpatne10 opened this issue 7 years ago • 0 comments
trafficstars

print(user) always prints None and the restaurant drop-down menu (/items/create/) is totally blank. Why is this happening? Here's the code from my forms.py of menus app. I've logged in and logged out time again and checked the code multiple times. But I still end up with this.

from django import forms
from restaurants.models import RestaurantLocation`
from .models import Item


class ItemForm(forms.ModelForm):
   class Meta:
       model = Item
       fields = [
            'restaurant',
            'name',
            'contents',
            'excludes',
            'public'
       ]

    def __init__(self, user=None, *args, **kwargs):
        # print(kwargs.pop('user'))
       print(user)
       super(ItemForm, self).__init__(*args, **kwargs)
       self.fields['restaurant'].queryset = RestaurantLocation.objects.filter(owner=user)

Django version 1.11.2, using settings 'muypicky.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CTRL-BREAK. None [11/Jul/2018 16:00:23] "GET /items/create/ HTTP/1.1" 200 2309 Performing system checks...

apoorvpatne10 avatar Jul 11 '18 10:07 apoorvpatne10