سؤال

I have a field with the name end_date, and when I try to use filter in my view:

c = Coursera.objects.filter(end_date__lt = datetime.date.today()).order_by('-date')[:1].get()

I get the following error:

Cannot resolve keyword 'date' into field. Choices are:...

end_ is being completely ignored; hence, I would assume that end is possibly a keyword; clearly, I can change the field name to something else; however, my question is: is there another way to still use that field name and be able to use the filter?

P.S. I thought keywords such as lt, or gt are only used after two underscores!

هل كانت مفيدة؟

المحلول

I do not think end_ is a keyword, error is probably because of order_by('-date'). Seems like you do not have a field date in your model but you are trying to fetch the result order by date field.

نصائح أخرى

import re
if not re.match(r'^[_]+$', username):
    raise forms.ValidationError("Sorry , you can only have  _  in username")
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top