Advertisement
horozov86

How to split into two models from Chat gpt

Apr 3rd, 2024
599
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.27 KB | None | 0 0
  1. СТРАННО НЕ ВИЖДАМ DELETE PLACE. МОЖЕ БИ СЪМ ГО ЗАБРАВИЛ!!!!!!!!!
  2.  
  3. from django.contrib.auth import get_user_model
  4. from django.db import models
  5.  
  6. UserModel = get_user_model()
  7.  
  8. class Category(models.Model):
  9.     CATEGORY_CHOICES = [
  10.         ('Mountain', 'Mountain'),
  11.         ('Sea', 'Sea'),
  12.         ('Historical Site', 'Historical Site'),
  13.         ('City', 'City'),
  14.         ('Spa', 'Spa'),
  15.         ('Wine Tourism', 'Wine Tourism')
  16.     ]
  17.  
  18.     category = models.CharField(max_length=100, choices=CATEGORY_CHOICES)
  19.  
  20.     def __str__(self):
  21.         return self.category
  22.  
  23. class Place(models.Model):
  24.     RATING_CHOICES = [
  25.         (1, '1 Star'),
  26.         (2, '2 Stars'),
  27.         (3, '3 Stars'),
  28.         (4, '4 Stars'),
  29.         (5, '5 Stars'),
  30.     ]
  31.  
  32.     hotel_name = models.CharField(
  33.         max_length=200,
  34.         null=False,
  35.         blank=False,
  36.         verbose_name="Hotel name",
  37.     )
  38.     description = models.TextField(
  39.         null=False,
  40.         blank=False,
  41.     )
  42.     location = models.CharField(
  43.         max_length=200,
  44.         null=False,
  45.         blank=False,
  46.     )
  47.     rating = models.IntegerField(
  48.         choices=RATING_CHOICES,
  49.         null=True,
  50.         blank=True,
  51.     )
  52.  
  53.     image_url = models.ImageField(upload_to="mediafiles/photos", null=True, blank=True,)
  54.  
  55.     category = models.ForeignKey(Category, on_delete=models.CASCADE)
  56.  
  57.     user = models.ForeignKey(UserModel, on_delete=models.CASCADE)
  58.  
  59. from django import forms
  60. from my_holiday.destination.models import Place, Category
  61.  
  62. class PlaceBaseForm(forms.ModelForm):
  63.     class Meta:
  64.         model = Place
  65.         fields = ['hotel_name', 'description', 'location', 'rating', 'image_url', 'category']
  66.         widgets = {
  67.             'hotel_name': forms.TextInput(attrs={'placeholder': 'Enter hotel name...'}),
  68.             'description': forms.Textarea(attrs={'placeholder': 'Enter short hotel description...'}),
  69.             'location': forms.TextInput(attrs={'placeholder': 'Fill hotel location...'}),
  70.         }
  71.  
  72. class PlaceCreateForm(PlaceBaseForm):
  73.     CATEGORY_CHOICES = Category.CATEGORY_CHOICES
  74.     category = forms.ChoiceField(choices=CATEGORY_CHOICES)
  75.  
  76. class PlaceDetailsForm(PlaceBaseForm):
  77.     pass
  78.  
  79. class PlaceEditForm(PlaceBaseForm):
  80.     pass
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement