Advertisement
horozov86

Ask SoftUni for my form

Mar 14th, 2024
535
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. from django import forms
  2. from django.views.generic.edit import CreateView
  3. from .models import Place
  4. from .models import Location, Category, Rating
  5.  
  6. class PlaceForm(forms.ModelForm):
  7. #   ТУКА ДЕФИНИРАМ ПОЛЕТАТА ОТ ДРУГИТЕ МОДЕЛИ class Location, class Category и class Rating
  8.     location = forms.ModelChoiceField(queryset=Location.objects.all())
  9.     category = forms.ModelChoiceField(queryset=Category.objects.all())
  10.     rating = forms.ModelChoiceField(queryset=Rating.objects.all())
  11.  
  12.     class Meta:
  13.         model = Place
  14.         fields = ['name', 'description', 'location', 'category', 'rating']
  15.  
  16. class PlaceCreateView(CreateView):
  17.     model = Place
  18.     form_class = PlaceForm
  19.     template_name = 'my_template.html'
  20.     success_url = '/success/'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement