Search Results

Search found 1 results on 1 pages for 'heyl1'.

Page 1/1 | 1 

  • Validation on ManyToManyField before Save in Models.py

    - by Heyl1
    I have the following models: class Application(models.Model): users = models.ManyToManyField(User, through='Permission') folder = models.ForeignKey(Folder) class Folder(models.Model): company = models.ManyToManyField(Compnay) class UserProfile(models.Model): user = models.OneToOneField(User, related_name='profile') company = models.ManyToManyField(Company) What I would like to do is to check whether one of the users of the Application has the same company as the Application (via Folder). If this is the case the Application instance should not be saved. The problem is that the ManyToManyFields aren't updated until after the 'post-save' signal. The only option seems to be the new m2m_changed signal. But I'm not sure how I then roll back the save that has already happened. Another option would be to rewrite the save function (in models.py, because I'm talking about the admin here), but I'm not sure how I could access the manytomanyfield content. Finally I've read something about rewriting the save function in the admin of the model in admin.py, however I still wouldn't know how you would access the manytomanyfield content. I have been searching for this everywhere but nothing I come across seems to work for me. If anything is unclear, please tell me. Thanks for your help! Heleen

    Read the article

1