I usually do product.id = None product.pk = None
But I'm not sure whether that's the best way to do it On Mon, Jan 11, 2016 at 4:25 AM, Xudong Zhang <[email protected]> wrote: > I want to delete the id attribute of a model but failed, it comlains that > the model has no attribute 'id'. But I use hasattr() checked it and it does > has the attribute. > > My sample code > > product = Product.objects.get(pk=_id) > if hasttr(product, 'id'): > del product.id > > I also tried delattr(product, 'id'), got same result. > > Exception Type: AttributeError Exception Value: > > 'Product' object has no attribute 'id' > > > I use python 3 and django 1.8. > > Anyone could help here? > > -- > 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 [email protected]. > To post to this group, send email to [email protected]. > 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/75e6687d-d7fe-4681-ba30-8ed74044a03e%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/75e6687d-d7fe-4681-ba30-8ed74044a03e%40googlegroups.com?utm_medium=email&utm_source=footer> > . > 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 [email protected]. To post to this group, send email to [email protected]. 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/CALn3ei2i%3DZXifi7RW6tochQM7kEoamU2%3D%2BFfQxxSbxpriKBQfw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.

