djangae ImageField无法使用CloudStorage

时间:2016-11-28 21:22:48

标签: google-app-engine django-models google-cloud-storage google-cloud-platform

我正在使用Djangae在google appengine上运行我的应用程序,我试图将图像存储到Google CloudStorage,

我遵循了here提到的相同的确切行程,但没有在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

ModelForm:

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>

1 个答案:

答案 0 :(得分:0)

这就是您要做的一切:

unsigned int