About useing photo in django
from django.db import models
# Create your models here.
class Food (models.Model):
name=models.CharField(max_length=100)
tozih=models.CharField(("tozih"), max_length= 50)
rate=models.IntegerField(("score"))
price=models.IntegerField()
pub=models.DateField(("when"), auto_now= False , auto_now_add= True)
p2hoto=models.ImageField(upload_to='foods/' , max_length= 20000 )
i want to in my admin page upload a image but is giving me this
You migrated before add the p2hoto field and add save some data in Food model, so when you add this field and migrate, those data want an image because your p2hoto field isn't null and doesn't have any default item. Do one of these:
1:
- Set default to the p2hoto field:
p2hoto=models.ImageField(upload_to='foods/' , max_length= 20000, default='you-image-path')
2:
- Set null to the field:
p2hoto=models.ImageField(upload_to='foods/', max_length=20000, null=True