Thanks you all Snejy and James.
Regards
>
--
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+unsubscr...@googlegroups.com.
To post to this group,
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
You probably don't want to use the name directly, you should probably look
at creating a slug from the name and store it in a SlugField on your model.
https://docs.djangoproject.com/en/1.8/ref/models/fields/#slugfield
https://docs.djangoproject.com/en/1.8/ref/utils/#module-django.utils.text
Your
Hi evrybody,
Here is my model:
# fruits/models
Class Fruit (models.Model):
name = models.CharField(max_length = 33,
choices = NAME_CHOICES, default = MANGO)
# and so on...
# fruits/views
def fruit(request, fruit_name):
fruit =
5 matches
Mail list logo