모델을 만들 때 (또는 저장시) nullable (null=True
) 필드가 필요하도록 만들 수있는 방법이 있는지 알고 싶습니다.Django Fake Required Fields
수퍼 유저로서 다른 직원이 할 수없는 동안 특정 필드를 null로 남겨 둘 수 있기를 바랍니다.
그런 식으로 할 수있는 방법이 있습니까?
미리 감사드립니다.
편집 :
분명히 내가 뭔가 잘못하고 있어요.
내가 모두 StudentChangeForm
및 StudentCreationForm
이 정확한 __init__
이 있습니다
class StudentAdmin(UserAdmin):
form = StudentChangeForm
add_form = StudentCreationForm
...
class Meta:
model = Student
def get_form(self, request, obj=None, **kwargs):
kwargs.update({'user': request.user})
# What's supposed to be here?
내가 이미 시도 많은 변화 :
def __init__(self, *args, **kwargs):
self.user = kwargs.pop('user', None)
super(StudentCreationForm, self).__init__(*args, **kwargs) # StudentChangeForm in StudentChangeForm (obviously)
if self.user.is_superuser:
self.fields['picture'].required = False
나는 또한 내 관리자의 Student
모델을 나타내는 StudentAdmin
클래스가 get_form
에 있고 올바른 것을 얻지 못하는 것 같습니다.
죄송합니다.
빠른 응답을 주셔서 감사합니다. 'not user.is_superuser'만이'required'가'True'가되도록 답을 편집 해 주시겠습니까?나는 그것을 어디에 넣어야 하는지를 이해하려고 노력 중입니다 ... – AnDrOiD
@AnDrOiD 예제가 업데이트되었습니다 –
보기'someview'는 어떻게 관련이 있습니까? 어떻게해야합니까? – AnDrOiD