Answer the question
In order to leave comments, you need to log in
How do I attach multiple photos to a post?
Hello!
There is a model, it is necessary that when creating a record, the user can attach their photos!
I see such an option (probably one of the simplest), is to add an additional QueryImage model, and use inlineformset_factory to make a form for images:
class Query(models.Model):
# к этой модели нужно прикрепить фото
# ...
class QueryImage(models.Model):
query = models.ForeignKey('Query', related_name='images', verbose_name=u'Запрос')
image = models.ImageField(u'Фото', upload_to='images/%Y/%m/%d')
comment = models.CharField(u'Комментарии', max_length=200, blank=True)
updated = models.DateTimeField(u'Изменен', auto_now=True)
created = models.DateTimeField(u'Создан', auto_now_add=True)
Answer the question
In order to leave comments, you need to log in
You have described a good one.
Instead of inline, you can throw in an API and send photos using AJAX (because, judging by the model, you do not limit the user to a specific number of photos).
By the way, use django-imagekit to compress photos (you don't know, maybe the user will want to send you a 400mb bitmap?)
And instead
use
image = ProcessedImageField(upload_to='your/path',
processors=[ResizeToFit(800, 600)],
format='JPEG', options={'quality': 70})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question