Answer the question
In order to leave comments, you need to log in
How to write CreateView for two related models?
I have two models Query and Files (for multiple file uploads). How should I write CreateView for Query so that the field for multiple file uploads is also displayed in the form!?
class Query(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE, default=0)
date_of_creation = models.DateTimeField(default=timezone.now)
query_text = models.TextField()
class Files(models. Model):
file = models.FileField(upload_to='files', blank=True, null=True, verbose_name="File")
files = models.ForeignKey(Query, blank=True, null=True, on_delete=models.CASCADE )
class Meta:
verbose_name = "Files"
verbose_name_plural = "Files"
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question