5

I have model with a OneToOneField that may be null:

solution_for = models.OneToOneField('QNAQuestion', related_name='solution', blank=True, null=True)

Sometimes it has a value that needs to be removed in a view. What is the syntax to null it? It's a very simple question, but google doesn't really help.

I already tried:

obj.solution_for = None
obj.solution_for = False
obj.solution_for = ''
del obj.solution_for

But I guess i have to give in.. What's the correct way to do this?

JasonTS
  • 2,479
  • 4
  • 32
  • 48

1 Answers1

6

Correct way is to set this field to None:

obj.solution_for = None
obj.save()
catavaran
  • 44,703
  • 8
  • 98
  • 85