django-forms

django - formset

故事扮演 提交于 2020-06-23 14:16:11
问题 please someone can explain for me a bit more about formset with its template , all my formsets only save the last form a appreciate your helps class Name(models.Model): name = models.CharField(unique=True,max_length=50) date = models.DateTimeField(auto_now_add=True) def __str__(self): return self.name forms.py class NameForm(ModelForm): class Meta: model = Name fields = '__all__' NameFormSet = modelformset_factory(Name,form=NameForm,extra=1,max_num=10) my template <button class="btn-block mt

Django - CheckboxSelectMultiple shows object representation instead of object's name

放肆的年华 提交于 2020-06-18 11:25:55
问题 So I am trying to have a list of checkboxes of cities, but instead of showing the cities' name, it shows this: How to make it shows the name instead of City object ? 回答1: In your model you have to include __str__ for python3 and unicode for python 2 For example python 3: class City(models.Model): name = forms.CharField(max_length=200, default="") def __str__(self): return self.name Python 2 class City(models.Model): name = forms.CharField(max_length=200, default="") def __unicode__(self):

Django - CheckboxSelectMultiple shows object representation instead of object's name

末鹿安然 提交于 2020-06-18 11:24:31
问题 So I am trying to have a list of checkboxes of cities, but instead of showing the cities' name, it shows this: How to make it shows the name instead of City object ? 回答1: In your model you have to include __str__ for python3 and unicode for python 2 For example python 3: class City(models.Model): name = forms.CharField(max_length=200, default="") def __str__(self): return self.name Python 2 class City(models.Model): name = forms.CharField(max_length=200, default="") def __unicode__(self):

Django - CheckboxSelectMultiple shows object representation instead of object's name

情到浓时终转凉″ 提交于 2020-06-18 11:23:45
问题 So I am trying to have a list of checkboxes of cities, but instead of showing the cities' name, it shows this: How to make it shows the name instead of City object ? 回答1: In your model you have to include __str__ for python3 and unicode for python 2 For example python 3: class City(models.Model): name = forms.CharField(max_length=200, default="") def __str__(self): return self.name Python 2 class City(models.Model): name = forms.CharField(max_length=200, default="") def __unicode__(self):

Django - CheckboxSelectMultiple shows object representation instead of object's name

狂风中的少年 提交于 2020-06-18 11:22:06
问题 So I am trying to have a list of checkboxes of cities, but instead of showing the cities' name, it shows this: How to make it shows the name instead of City object ? 回答1: In your model you have to include __str__ for python3 and unicode for python 2 For example python 3: class City(models.Model): name = forms.CharField(max_length=200, default="") def __str__(self): return self.name Python 2 class City(models.Model): name = forms.CharField(max_length=200, default="") def __unicode__(self):

Changing image in django user change form

心不动则不痛 提交于 2020-06-17 13:05:10
问题 I am making a django webapp where users can upload profile image. I have also created an EDIT PROFILE page by using the default USERCHANGEFORM . But the problem is, that I cannot update the profile picture from that form. I can delete it but not upload new one? Help needed. This is my USER CREATION FORM : class SignUpForm(UserCreationForm): photo = forms.ImageField(required=False) bio = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Enter your bio'})) designation = forms

Putting Submit button at the bottom of the form

做~自己de王妃 提交于 2020-06-17 09:37:05
问题 I want the submit button to be at the bottom of the form. I have tried using <div> , <div float="left"> , <div float="right"> , <br> and <span> . So far the only solution I have come up with is to repeat <br> multiple times which is a messy solution and one that is only compatible on laptops the same size as mine. <form method="post" action=""> {% csrf_token %} {% for hidden in form.hidden_fields %} {{ hidden }} {% endfor %} <div float="left"> {# Include the visible fields #} {% for field in

How to edit user's profile page on django?

℡╲_俬逩灬. 提交于 2020-06-17 08:05:31
问题 My django project has multiple functions, one of them lets the user update its profile(User model"first_name, username and email" Profile model" bio and profile picture") this used to perfectly work until I added a follow sistem, it is like the whole Profile and User model doesnt exist anymore so when trying to edit those fields, the code returns a AttributeError: 'User' object has no attribute 'profile' error, saying this line of code on the views.py file is wrong form1 = UpdateProfileForm

django modelform with bootstrap

放肆的年华 提交于 2020-06-11 11:46:10
问题 I want to format my modelforms with bootstrap, and without any additional packages (just using the bootstrap source files). A particular form that I want configured: class FoodForm(forms.ModelForm): class Meta: model = Food fields = ['name', 'company'] exclude = ('user', 'edit') The 'name' is a text field I'd want to be a bootstrap text field, and 'company' is a selection field (from a foreign key) that I'd want to be a bootstrap dropdown. The current setup of the form template: {% extends

django modelform with bootstrap

独自空忆成欢 提交于 2020-06-11 11:46:07
问题 I want to format my modelforms with bootstrap, and without any additional packages (just using the bootstrap source files). A particular form that I want configured: class FoodForm(forms.ModelForm): class Meta: model = Food fields = ['name', 'company'] exclude = ('user', 'edit') The 'name' is a text field I'd want to be a bootstrap text field, and 'company' is a selection field (from a foreign key) that I'd want to be a bootstrap dropdown. The current setup of the form template: {% extends