With django-rest-framework how do I assign a field to the request user when using a ModelViewSet? -


APIViews के लिए अनुशंसा:

  def pre_save (स्वयं, obj): obj.owner = Self.request.user   

यह काम करता है जैसे कि मैं वापस आ रहा है:

  { "स्वामी": ["यह फ़ील्ड रिक्त नहीं हो सकती।" ]}   

संपादित करें: pre_save विधि को कभी भी नहीं कहा जाता है pre_save विधि में pdb को कॉल डालने के द्वारा चेक किया गया।

मेरी धारावाहिक एक आदर्श हाइपरलिंक मॉडेलसेरियलाइज़र है जिसमें मॉडल और मेटा में निर्दिष्ट फ़ील्ड की सूची है।

मेरे मॉडल पर मैंने ओवरराइड किया है clean_fields clean_fields के लिए हस्ताक्षर:

  Model.clean_fields (बाहर के = कोई नहीं)   

मेरा कस्टम clean_fields : <पूर्व> def clean_fields (स्वयं, बाहर नहीं = कोई नहीं): सुपर (आवेदक, स्वयं) .clean_fields () # यहां बग # कस्टम क्लीन_फ़ील्ड कोड

मैंने बहिष्कार पैरामीटर को सुपर वर्ग में नहीं दिया!

हे भगवान, मुझे कई घंटे लगे डिबग करने के लिए

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -