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
Post a Comment