Tuesday, December 30, 2014

Re: delete OnetoOneField link

thank you. you give me more confidence

вторник, 30 декабря 2014 г., 17:19:53 UTC+3 пользователь Vijay Khemlani написал:
If you want to change a user's cashbox then yes, you would need to use your solution, but it's easier to get c1 by just saying

c1 = user.cashbox

instead of Cashbox.objects.get....

A more definite solution would be to add the OneToOne relation to the User model instead of the Cashbox object, but I'm not sure how that works in your project.

On Tue, Dec 30, 2014 at 6:56 AM, madjardi <malinich...@gmail.com> wrote:
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 django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
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.

--
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4f327604-9cf0-4ba2-95f4-e2f116f75867%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment