Answer the question
In order to leave comments, you need to log in
How to make a specific field by user in django?
Hello. There is a model:
class Numbers(models.Model):
title = models.CharField(max_length=200, verbose_name="Название",unique=True)
hotel = models.ForeignKey(Hotels, blank = True, verbose_name='Отель или гостевой дом, если есть')
slug = models.SlugField(verbose_name="URL")
sleep_place = models.IntegerField(verbose_name='Спальных мест')
room = models.IntegerField(verbose_name='Количество комнат')
image = models.ImageField(default = 'Noimage', verbose_name="Главное фото")
user = models.ForeignKey(User)
class NumbersForm(forms.ModelForm):
class Meta:
model = Numbers
fields = '__all__'
exclude = ['user']
class NumberCreate(CreateView):
model = Numbers
template_name = 'add_numbers.html'
form_class = NumbersForm
success_url = '/user/success'
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question