Django ManyToMany model validation

前端 未结 3 915
醉梦人生
醉梦人生 2020-12-02 20:30

I have a model with a ManyToManyField similar to this one (the model Word has a language, too):

class Sentence(models.Model):
    words = models.ManyToManyFi         


        
3条回答
  •  北海茫月
    2020-12-02 20:43

    You can't do it from the clean method on the model. It's simply not possible with the way M2M relationships work in Django. However, you can do this sort of validation on forms used to create a Sentence such as in the admin or a form on your site.

提交回复
热议问题