Wednesday, July 26, 2017

Re: Dynamic Model ID cannot be called

Nothing wrong with your function based view. Just try to fill data in DB field. It will work. Because you don't have any record in DB. Try to use 'get_or_create' function.


M

On Wed, Jul 26, 2017 at 4:50 AM, Shazia Nusrat <shazianusra@gmail.com> wrote:
Hi,

I have a simple model like below:

class Artists(models.Model):
       name = models.CharField(max_length=200)
       description = models.TextField()

       def __unicode__(self):
             return self.name

I am trying to call it in my view like below:

def artistdetail(request, id):
           artista = Artist.objects.get(id=id # this line is giving me error.


Can someone explain me how to get the id in operational mode. I can call IDs with filtering by name in shell. But how to set it up for the user who uses it.


Regards,
Shazia

--
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-users@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/CAD83tOyL_Sdi3eeuManMXnsNBXHhvpwzGA0Tt2qXX_MgAbOUaQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
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-users@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/CANoUts5nmSEeqNVa-%2B-vZ%3DPtmndnkDG%2B5gehMjA1r208u6ggxQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment