Advertisement
pacho_the_python

Untitled

Jun 24th, 2023
744
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.87 KB | None | 0 0
  1. from django import forms
  2.  
  3. from exam_23_06.web.models import Profile, Fruit
  4.  
  5.  
  6. class ProfileCreateForm(forms.ModelForm):
  7.     class Meta:
  8.         model = Profile
  9.         fields = ['first_name', 'last_name', 'email', 'password']
  10.         widgets = {
  11.             'first_name': forms.TextInput(attrs={'placeholder': 'First Name'}),
  12.             'last_name': forms.TextInput(attrs={'placeholder': 'Last Name'}),
  13.             'email': forms.EmailInput(attrs={'placeholder': 'Email'}),
  14.             'password': forms.PasswordInput(attrs={'placeholder': 'Password'}),
  15.         }
  16.         labels = {
  17.             'first_name': '',
  18.             'last_name': '',
  19.             'email': '',
  20.             'password': '',
  21.         }
  22.  
  23.  
  24. class FruitCreateForm(forms.ModelForm):
  25.     class Meta:
  26.         model = Fruit
  27.         fields = '__all__'
  28.         widgets = {
  29.             'name': forms.TextInput(attrs={'placeholder': 'Fruit Name'}),
  30.             'image_url': forms.URLInput(attrs={'placeholder': 'Fruit Image URL'}),
  31.             'description': forms.TextInput(attrs={'placeholder': 'Fruit Description'}),
  32.             'nutrition': forms.TextInput(attrs={'placeholder': 'Nutrition Info'}),
  33.         }
  34.         labels = {
  35.             'name': '',
  36.             'image_url': '',
  37.             'description': '',
  38.             'nutrition': '',
  39.         }
  40.  
  41.  
  42. class FruitEditForm(forms.ModelForm):
  43.     class Meta:
  44.         model = Fruit
  45.         fields = '__all__'
  46.  
  47.  
  48. class FruitDeleteForm(forms.ModelForm):
  49.     def __init__(self, *args, **kwargs):
  50.         super().__init__(*args, **kwargs)
  51.         for _, field in self.fields.items():
  52.             field.widget.attrs['disabled'] = 'disabled'
  53.             field.widget.attrs['readonly'] = 'readonly'
  54.  
  55.     def save(self, commit=True):
  56.         self.instance.delete()
  57.         return self.instance
  58.  
  59.     class Meta:
  60.         model = Fruit
  61.         fields = '__all__'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement