class PrintshopProfileForm(forms.ModelForm):
class Meta:
model = PrintShop
fields = ('name_printing', 'detail_text', 'logo', 'phone', 'country', 'city', 'address')
widgets = {
'name_printing': forms.TextInput(attrs={'class': 'form-control'}),
'detail_text': forms.Textarea(attrs={'class': 'form-control','rows':'5'}),
'phone': forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Телефон'}),
'country': forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Страна'}),
'city': forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Город'}),
'address': forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Адрес'})
}
site = forms.URLField(initial='http://')
class PrintShop(models.Model):
# email записываем в стандартное свойство User
# Имя и Фамилию контактного лица записываем в стандартное свойство User
user = models.OneToOneField(User, on_delete=models.CASCADE, related_name="PrintShopProfile")
name_printing = models.CharField(max_length=100, blank=False)
detail_text = models.TextField(blank=True)
is_active = models.BooleanField(default=False)
key_activate = models.CharField(max_length=20, blank=True, null=True)
site = models.URLField(blank=True)
logo = models.FileField(upload_to='logo/', blank=True)
phone = models.CharField(max_length=100, blank=False)
country = models.CharField(max_length=100, blank=False)
city = models.CharField(max_length=100, blank=False)
address = models.CharField(max_length=100, blank=False)
# В будущем стоит внедрить готовый модуль специального поля для
# номеров телефонов https://github.com/stefanfoulis/django-phonenumber-field
#city = https://github.com/coderholic/django-cities
#services = models.ManyToManyField('services.Service', blank=True) # В дальнейшем будем связывать с услугами
def __str__(self):
return "%s" % self.user
class Meta:
verbose_name = "Профиль исполнителя"
verbose_name_plural = "Профили исполнителей"
def edit_profile_printing(request):
profile_data = get_object_or_404(PrintShop, user=request.user)
edit_form = PrintshopProfileForm(instance=profile_data)
if request.POST:
edit_form.save()
return redirect('/')
return render(request, 'profile/profile_printing.html', {'editForm':edit_form})_form})