init queryset return 'expected string or buffer'

16 views
Skip to first unread message

احسان خراسانی

unread,
Nov 12, 2016, 6:07:49 PM11/12/16
to Django users
Hi
my queryset return this error
expected string or buffer


class Reserve(forms.ModelForm):
    food_name
= forms.ModelChoiceField(queryset=Food.objects.all())

   
def __init__(self, year=None, month=None, day=None, serve_date=None, *args, **kwargs):
       
super(Reserve, self).__init__(*args, **kwargs)
       
self.year = year
       
self.month = month
       
self.day = day
       
self.serve_date = serve_date
        date_stamp
=  time.strptime(serve_date,"%Y-%m-%d")
        serve_date
= datetime.date(*date_stamp[:3])
       
self.fields['food_name'].queryset = Food.objects.filter(
            serve_date__year
= year, serve_date__month = month, serve_date__day = day)

   
class Meta:
        model
= Reservation
        fields
= ('food_count', 'food_name')


ADEWALE ADISA

unread,
Nov 13, 2016, 12:43:45 PM11/13/16
to django...@googlegroups.com

May be you should show your reservation model class. Because there, if you make your food_name field to be equal to a foreignKey(Food), your form class would be easier to write

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0fac06b1-181c-45cf-8ba2-871f6a4beed7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ADEWALE ADISA

unread,
Nov 13, 2016, 12:44:04 PM11/13/16
to django...@googlegroups.com

I think the argument to modelchoicefield  should be dictionary of string not query set object.

On Nov 13, 2016 12:08 AM, "احسان خراسانی" <moham...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages