내가 아래 모델을 가지고 내가하려고 할 때 내가 many2many 필드액세스 many2many 필드 값 깨끗한 방법으로 데이터베이스에 저장하기 전에
RULE_SET_CHOICES = (
('G', 'GLOBAL'),
('C', 'LOCAL')
)
class Books(models.Model):
type = models.CharField(max_length=2, choices=RULE_SET_CHOICES, null=False, default='C')
author = models.ManyToManyField(Author, related_name="books", blank=True, null=True)
def clean(self):
if self.type = 'G':
// Check if type is Global and if we tried to associate/add authors then raise a validation error
if self.author :
raise ValidationError("When type is global, you should not associate authors")
의 값에 따라 청소 방법의 유효성 검사 오류를 높이기 위해 노력하지만,하고 장고 액세스 self.author
에 나는
*** ValueError: "<Books: Hello World- G>" needs to have a value for field "author " before this many-to-many relationship can be used
그래서 데이터베이스에 저장하기 전에 많은-2-많은 관계 필드 값에 액세스 할 수있는 방법이 오류 아래에 직면하고있다? 위와 같이 해당 값을 기준으로 유효성 검사 오류를 발생시켜야하므로