You can do
fruit = get_object_or_404(Fruit, name=fruit_name)
but i wont recommend doing this with field that is not unique because it
basically resolves to Fruit.objects.get(name=fruit_name) which will raise
error if there are two objects with the same name... Furthermore you have
choices..
If I understand the question correct..
you can do
fruit = get_object_or_404(Fruit, name=fruit_name) even if its not SlugField.
I dont recommend doing that with field that doesn't have unique=True
because error will be raised if there are more than one objects with this
name.
(This equals
2 matches
Mail list logo