카테고리 없음

[장고] 장고 인라인 관리 모델 및 일반 관계

행복을전해요 2020. 12. 13. 15:22

내가 당신을 이해한다면 다음과 같은 것이 작동합니다.

class MyModelForm(forms.ModelForm):
    class Meta:
            model = MyModel
            
                def clean(self):
                        content_type = self.cleaned_data.get('content_type')
                                object_id = self.cleaned_data.get('object_id')
                                
                                        if content_type and object_id:
                                                    obj = content_type.get_object_for_this_type(pk=object_id)
                                                                # Check whatever on the object here, and if there's a problem:
                                                                            # raise forms.ValidationError('Something is not right')
                                                                            
                                                                                    return self.cleaned_data
                                                                                    


출처
https://stackoverflow.com/questions/7415087