Django OneToOneField deleting child doesn't set parents parameter as None? -


i have 2 models in django app

class product(models.modelfield):   name = ...  class discount(models.modelfield):   product_id = models.onetoonefield(product) 

basically, each product can have optional discount.now, assume have 1 product p discount d attached. want delete discount associated product p. so, use

p.discount.delete() 

while makes discount.objects.all() return [], p.discount still associated discount object.

how set attribute none?

p.discount = none 

changing in database not affect model instances in memory. in 1.8 can reload object db:

p.refresh_from_db() 

or before 1.8:

p = product.objects.get(pk=p.pk) 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -