django - how to check in a clean method of a form whether it is an insert or an update -
I have a form where I clearly agree that a project ambership object already exists, whose project There is equal value for the member. This is the reason that I have defined the unique_tagent barrier for the project and member in the Project Membership model. It actually works fine.
But now I'm asking myself how can I decide how well the user tries to make a new relationship or update the relationship. Because it is not possible to update this clearly, because this error message indicates that the entry already exists
If ProjectMembership.objects Filters (Project = Project, Member = Member). Calculate ()> 0:
To do something like this:
If ProjectMembership.objects.filter (project = project, member = member) .exclude (pk = self Instance.id) .Count ()> 0:
Actually you need to know if you do not own it before using it to take it out. There is no one, but hopefully this little snippet has given you some idea how your task can be completed without duplicating the form.
Comments
Post a Comment