我的表格中的值似乎没有在我的表格中正确插入。以下是我的代码: -
## my Forms.py ##
class AerialPhotoForm(forms.ModelForm):
class Meta:
model = AerialFoto
fields = ['year_id', 'scale_id', 'index_id', 'location_id', 'size']
## my Views.py ##
if request.method == 'POST':
form = AerialPhotoForm(request.POST)
if form.is_valid():
form.save()
## my Models.py ##
class AerialFoto(models.Model):
AerialFoto_id = models.AutoField(primary_key=True)
index_id = models.ForeignKey(No_index, null=True, blank=True)
scale_id = models.ForeignKey(Scale, null=True, blank=True)
location_id = models.ForeignKey(Location, null=True, blank=True)
year_id = models.ForeignKey(Year, null=True, blank=True)
file_directory = models.CharField(max_length=255)
size = models.DecimalField(max_digits=19, decimal_places=2, blank=True, null=True)
gsd = models.CharField(max_length=7)
我得到的结果是: -
答案 0 :(得分:0)
要查看对象的详细表达式,您需要在模型中定义__unicoide__
(或__str__
if python 3.x)方法:
class Location(models.Model):
...
name = models.CharField.....
def __unicode__(self): # or __str__ if python 3
return self.name # assuming you have a name field, you can use any string field.
# You could return any string here to test
# e.g. return 'This is my object'
No_Index
,Scale
和Year
模型也是如此。