This is a question about Form in Django.

Asked 1 years ago, Updated 1 years ago, 85 views

I am posting because I have a question on the django regular form.

In the book I'm reading now, the content of the model class is

class Album(models.Model):
    name=models.CharField(max_length=50)
    description=models.CharField('One Line Description', max_length=100,blank=True)

class Photo(models.Model):
    album=models.ForeignKey(Album)
    title=models.CharField(max_length=50)
    image=ThumbnailImageField(upload_to='photo/%Y/%m')
    description=models.TextField('Photo Description',blank=True)
    upload_data=models.DateTimeField('Upload Date',auto_now_add=True)

Forms the model class of .Map to py

from django import forms

class PhotoForm(forms.Foms):
    album=forms.ModelChoiceField(queryset=Album.objects.all())
    title=froms.CharField(max_length=50)
    image=ImageField()
    description =forms.CharField(label='Photo Description', widget=forms.Textarea,required=False)
    upload_date=forms.DateTimeField(label='Upload Date')

I heard that if you make a code like this, it can be mapped, so I wonder how it can be mapped. Does it work automatically? Model Forms designates the model in class meta, but please tell me how to designate the regular form ㅜ.ㅜ

forms django

2022-09-22 20:24

1 Answers

For generic forms, in generic form view

form_class = PhotoForm

You can assign it this way.


2022-09-22 20:24

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.