Custom model validation for many to many field in django -


hi there have model this:

class team(models.model):     owner = models.foreignkey(user)     members = models.manytomanyfield(user) 

now 1 owner can have multiple teams particular member belong 1 team. let's if there team member john, user can't create team same member again.

for that, trying add custom model field validation:

def clean_fields(self, exclude=none):         super(mentorteam, self).clean_fields(exclude=exclude)         self.candidates # returns error because team instance not saved yet.  

how can validation?

by definition, manytomany relationship means member can belong many teams.

what should do foreignkey team user model:

class user(models.model):     team = models.foreignkey(team, related_name='members')     ... 

hope helps!


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -