I would use signals for that purpose
On 11-02-11 10:18, bagheera wrote:
Hi, i would like to perform validation on m2m field to control, if
user made any changes. I'd like to disallow removing relations from
m2m field, only adding them.
example:
model Product(models.Model):
name = models.TextField()
model Order(models.Model):
products = models.ManyToManyField(Product)
If user creates an order with three products, he can't remove any
product from order after object has been saved.
Is there any way to do that on model level?
if i put in clean() method:
current_products = self.products.all() i will get list of products
currently assigned to order. Can i get list of objects that was chosen
in form, so i could compare them and raise validation error if needed?
--
blog http://piotr.zalewa.info
jobs http://webdev.zalewa.info
twit http://twitter.com/zalun
face http://www.facebook.com/zaloon
--
You received this message because you are subscribed to the Google Groups "Django
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.