class Cashbox(models.Model):
    cashier = models.OneToOneField('User', null=True, blank=True, 
related_name='cashbox', on_delete=models.SET_NULL)

in other code:
User.object.get(pk=1)
user.cashbox = None

AttributeError: 'NoneType' object has no attribute 'cashier_id'

one version solving is:
c1 = Cashbox.objects.get(pk=user.cashbox.id)
c1.cashier = None
c1.save()


c2 = Cashbox.object.get(pk=10)
c2.cashier = user
c2.save()


i need get other Cashbox to set link None. Why i need do so. is there a 
better solution.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9bac63fa-64e3-4353-82ae-6b31fa8f281f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to