djangae ImageField ไม่ทำงานกับ CloudStorage

ฉันใช้ Djangae เพื่อรันแอปพลิเคชันของฉันบน google appengine ฉันกำลังพยายามจัดเก็บรูปภาพไปที่ google CloudStorage

ฉันทำตามขั้นตอนเดียวกันทุกประการที่กล่าวถึงที่นี่ แต่ไม่มีอะไรเขียนไว้ CloudStorage ไม่มีข้อผิดพลาดไม่มีข้อยกเว้น!

นี่คือคลาสโมเดลที่ฉันมี:

class Person(models.Model):
    user = models.ForeignKey(User, default=1)
    name = models.CharField(max_length=250,null=True)
    last_name = models.CharField(max_length=500)
    age= models.IntegerField(default=100)
    martial_status = models.CharField(max_length=20, choices=STATUS_CHOICES, default=("Single"))
    sex = models.CharField(max_length=20, choices=SEX_CHOICES, default=("Male"))
    mobile=models.CharField(max_length=26,default=0011)
    amount_paid=models.CharField(max_length=256,null=True)
    amount_left = models.CharField(max_length=256, null=True,blank=True)
    note=models.CharField(max_length=256,null=True,blank=True)
    address=models.CharField(max_length=256,null=True,blank=True)
    date = models.DateField(("Date"), default=date.today,blank=True)
    chief_complain = models.CharField(max_length=256,null=True,blank=True)
    treatment_plan=models.CharField(max_length=256,null=True,blank=True)
    treatment_done=models.CharField(max_length=256,null=True,blank=True)
    #picture = models.ImageField(blank=True)
    picture = models.ImageField(upload_to='/image/', storage=public_storage,blank=True)
    def __str__(self):
        return self.name

โมเดลฟอร์ม :

class PersonForm(forms.ModelForm):

    class Meta:
        model = Person
        fields = ['name', 'last_name', 'age', 'martial_status', 'mobile', 'sex',
                  'amount_paid','amount_left','note', 'address','date','picture','treatment_done','treatment_plan','chief_complain']
        widgets = {
            'name': forms.TextInput(attrs={'required': True, 'class': 'form-control',
                                             'placeholder': 'name'}),
            'last_name': forms.TextInput(attrs={'required': True, 'class': 'form-control',
                                           'placeholder': 'lastname'}),
            'age': forms.TextInput(attrs={'required': True, 'class': 'form-control',
                                           'placeholder': 'age'}),
            'amount_paid': forms.TextInput(attrs={'required': True, 'class': 'form-control',
                                           'placeholder': 'amount paid'}),
            'amount_left': forms.TextInput(attrs={'required': True, 'class': 'form-control',
                                           'placeholder': 'amount left'}),
            'note': forms.TextInput(attrs={'required': False, 'class': 'form-control',
                                           'placeholder': 'Patient History'}),
            'address': forms.TextInput(attrs={'required': False, 'class': 'form-control',
                                           'placeholder': 'Current address'}),
            'chief_complain': forms.TextInput(attrs={'required': False, 'class': 'form-control',
                                           'placeholder': 'chief complain'}),
            'treatment_plan': forms.Textarea(attrs={'required': False, 'class': 'form-control',
                                           'placeholder': 'treatment plan','rows':'3'}),
            'treatment_done': forms.Textarea(attrs={'required': False, 'class': 'form-control',
                                           'placeholder': 'treatment done','rows':'3'}),




        }

แม่แบบ :

<h2>Add person</h2>
  <form method="post">
    {% csrf_token %}


<div class="row">
     <div class="col-sm-4 form-group">
       <label for="name" >{% trans "Name" %}</label>
       {{ form.name|add_class:"form-control" }}
      </div>

..<code snippet>..

      <div class="row">
       <div class="col-sm-4 form-group">
       <label for="address">{% trans "Address" %}</label>
       {{ form.address|add_class:"form-control" }}
      </div>
          <div class="col-sm-4 form-group">
       <label for="pic">{% trans "Picture" %}</label>
        {{form.picture}}
      </div>
      </div>

comment
คุณได้ระบุ CLOUD_STORAGE_BUCKET ในการตั้งค่าของคุณหรือไม่? อาจกำหนดให้ต้องระบุฟิลด์ picture เพื่อที่คุณจะได้มองเห็นข้อผิดพลาดเมื่อมีการโยนทิ้ง   -  person atimothee    schedule 01.12.2016
comment
คุณเคยคิดหาวิธีแก้ปัญหาบ้างไหม OP?   -  person pdoherty926    schedule 05.03.2019


คำตอบ (1)


นั่นคือทั้งหมดที่คุณต้องทำ:

from djangae import fields, storage

public_storage = storage.CloudStorage(
bucket='my_project_id.appspot.com', google_acl='public-read')

class Picture(models.Model):
    picture = models.FileField(upload_to='image', storage=public_storage, blank=True)
person Ali Aqrabawi    schedule 05.03.2019