Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django import forms
- from exam_23_06.web.models import Profile, Fruit
- class ProfileCreateForm(forms.ModelForm):
- class Meta:
- model = Profile
- fields = ['first_name', 'last_name', 'email', 'password']
- widgets = {
- 'first_name': forms.TextInput(attrs={'placeholder': 'First Name'}),
- 'last_name': forms.TextInput(attrs={'placeholder': 'Last Name'}),
- 'email': forms.EmailInput(attrs={'placeholder': 'Email'}),
- 'password': forms.PasswordInput(attrs={'placeholder': 'Password'}),
- }
- labels = {
- 'first_name': '',
- 'last_name': '',
- 'email': '',
- 'password': '',
- }
- class FruitCreateForm(forms.ModelForm):
- class Meta:
- model = Fruit
- fields = '__all__'
- widgets = {
- 'name': forms.TextInput(attrs={'placeholder': 'Fruit Name'}),
- 'image_url': forms.URLInput(attrs={'placeholder': 'Fruit Image URL'}),
- 'description': forms.TextInput(attrs={'placeholder': 'Fruit Description'}),
- 'nutrition': forms.TextInput(attrs={'placeholder': 'Nutrition Info'}),
- }
- labels = {
- 'name': '',
- 'image_url': '',
- 'description': '',
- 'nutrition': '',
- }
- class FruitEditForm(forms.ModelForm):
- class Meta:
- model = Fruit
- fields = '__all__'
- class FruitDeleteForm(forms.ModelForm):
- def __init__(self, *args, **kwargs):
- super().__init__(*args, **kwargs)
- for _, field in self.fields.items():
- field.widget.attrs['disabled'] = 'disabled'
- field.widget.attrs['readonly'] = 'readonly'
- def save(self, commit=True):
- self.instance.delete()
- return self.instance
- class Meta:
- model = Fruit
- fields = '__all__'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement