django-forms

Creating a User Profile page using OneToOne field with User Model

∥☆過路亽.° 提交于 2019-12-25 08:47:24
问题 I'm currently using Django all-auth, and it has a /accounts/profile page which I want to create/populate with a form which updates user information. I have a Teacher field, which extends the User Model using OneToOne field. models.py class Teacher(models.Model): user = models.OneToOneField(User, on_delete=models.PROTECT, related_name='Teacher') bio = models.TextField(max_length=500, blank=True) availability = models.BooleanField(default=False) teacher_logo = models.FileField() This teacher

Allauth login on homepage not working

此生再无相见时 提交于 2019-12-25 08:28:52
问题 To allow Django's allauth to work on my homepage, I copied the allauth HTML for the login and signup forms to my own base.html (The login form can be seen here). So this successfully renders the form and its fields on my homepage. However, when I click submit on the login form, it just redirects me to allauth's /accounts/login URL, which renders the same form. Only after that does submitting the form work. It's the same with the signup form when I submit the signup form on my homepage, it

CheckboxSelectMultiple validation error when submitting the form on Django

纵饮孤独 提交于 2019-12-25 08:27:33
问题 models.py class MyModel(models.Model): OPTION_CHOICES = (('a','a'),('b','b')) option = models.CharField(max_length=1, choices=OPTION_CHOICES) forms.py class MyForm(ModelForm): class Meta: model=MyModel fields=['option'] widgets = {'option':CheckboxSelectMultiple(),} When I try to submit the form, I have validation error and can't submit it. When I chance CheckboxSelectMultiple to RadioSelect it works just fine. So how can I fix this using checkboxSelectMultiple 回答1: option = models.CharField

Django: Check multiple choices with not fixed choices

笑着哭i 提交于 2019-12-25 07:35:39
问题 I am new to Django, and I am trying to create a multiple selection with checkboxes. The problem is that all of the examples that I found have fixed choices that are specified in the form, and I don't need that. More concretely, let this be a model for a simple car dealership app: class CarBrand(models.Model): name = model.CharField() class CarModel(models.Model): name = model.CharField() brand = model.ForeignKey(CarBrand) My goal is when I enter the page for Audi, I get options A3, A4, A5,

Django ForeignKey show data from PostgreSQL

蹲街弑〆低调 提交于 2019-12-25 07:25:53
问题 i have a db in PostgreSQL which is connecting 2 different tables lets call them TBL1 ( TBL1 is a table for all types ) and TBL2 ( TBL2 is a table for e.g. cars ), TBL1 and TBL2 have a same column named type , so i have created the foreign key between them. Because i'm not sure if that has anything to do with Django... So, now in model, i have created ( based on the form ) variable called type = models.ForeignKey('TBL1', db_column='type', related_name='type') and it's returning to me Django

Django - Show plot from SQLite database, accessed by form

主宰稳场 提交于 2019-12-25 06:58:49
问题 So I have a page written using Django where someone can enter information into a form, and on submit it accesses a SQLite database to retrieve the queried information. So far I have gotten this far, but I am not able to create and show a plot below the form on the page. I have tried different packages: ChartIt , Graphos and nvd3 . Either way I get an error, likely because I don't understand the full details of the coding in Django. Below is my try at creating a plot with nvd3. When I try to

Django fields assign to html fields

扶醉桌前 提交于 2019-12-25 06:38:16
问题 How to assign Django fields to html fields. Without adding {{form}} in html? The actual problem that I want my fields to look like this: But if I use this {{form}} , what I can get is I've created a custom form, can I assign my input fields from HTML to form class fields in Django? 回答1: simple answer You can have your own form not use {{ form }} just give the input tag. <input type="text" name="<your name"> Please note given name must match the your database field. yes of course you can

Combining a Form and a FormSet in Django

∥☆過路亽.° 提交于 2019-12-25 06:16:41
问题 I have a FormWizard that displays three parts of a registration application. The last part involves creating a group and adding members to it. I would like to present two forms at once on the same view. Group Builder class GroupBuilder(forms.Form): name = forms.CharField(max_length=30, widget=forms.TextInput(attrs={ 'placeholder': 'eg. The Underdogs'})) Member Builder class MemberBuilder(forms.Form): first_name = forms.CharField(max_length=128) last_name = forms.CharField(max_length=128) role

django model form inheritance

时光总嘲笑我的痴心妄想 提交于 2019-12-25 05:18:29
问题 I'm using django modelform inheritence in my modelform but it seems to be not working here is my code sample class ArticleForm(forms.ModelForm): title = forms.CharField(required=True) sites = forms.ModelMultipleChoiceField(required=True, queryset= Sites.objects.all().order_by('name'), widget=forms.SelectMultiple()) class ArticleAddForm(ArticleForm): class Meta(ArticleForm.Meta): exclude = ('sites',) i want to exclude "sites" from "ArticleAddForm" but while validating it is raising form

Django (Model)Form Field: Manytomany with key value pair

六眼飞鱼酱① 提交于 2019-12-25 05:10:05
问题 I have a situation where I need to do something similar to rendering a formset within a formset. But I'd rather focus on the problem before jumping to a solution. In English first: I'm creating a shipment from a warehouse. Each shipment can contain multiple lines (unique combinations of product_type and package_type) with an item_count However for each line there could be multiple "Packages" - a package_type of a product_type that has an item_count. Think of this as a batch. The customer is