django-forms

How can i add a onchange js event to Select widget in Django?

余生颓废 提交于 2020-05-16 06:05:08
问题 I need to attach a JavaScript onchange event to the receipt dropdown list in a Django project. When the value of the dropdown list is changed a JavaScript function is to be called. How can it be done? The form.py file is given below from django import forms receipt_types=(('option1','Option 1'),('option2','Option 2'),('option3','Option 3'),) class accountsInForm(forms.Form): receipt=forms.CharField(max_length=100, widget=forms.Select(choices=reciept_types)) 回答1: Change the code as follows :

Update instances of ModelFormset

筅森魡賤 提交于 2020-05-16 01:21:08
问题 In my django app two models are connecetd by manytomany relation and I am using modelformset_fatory to create a form like this Views.py def post(request): tform = TeamForm() pform = modelformset_factory(Player, form=PlayerForm, extra = 1) pform = pform(request.POST or None, queryset = Player.objects.filter(id__isnull = True)) if request.method == 'POST': t = Team() tform = TeamForm(request.POST, instance=t) if tform.is_valid() and pform.is_valid(): tform.save() instances = pform.save(commit

Django: request.user in form

会有一股神秘感。 提交于 2020-05-15 04:56:04
问题 How may I get the user details to use within a from? I know in the view I can just do: currentUser=request.user But if I use it in the form as so I get the following error "'request' is not defined". class SelectTwoTeams(BootstrapForm): currentUser=request.user date_joined = currentUser.date_joined.replace(tzinfo=pytz.utc) timeless30 = datetime.datetime.now() - datetime.timedelta(seconds=3610) timeless30 = timeless30.replace(tzinfo=pytz.utc) if date_joined > timeless30: currentCharities =

AttributeError: module Django.contrib.auth.views has no attribute

≯℡__Kan透↙ 提交于 2020-05-10 06:54:32
问题 In my Django app useraccounts, I created a Sign-Up form and a model for my Sign-up. However, when I went to run python manage.py makemigrations, I encounter the error: AttributeError: module Django.contrib.auth.views has no attribute 'registration'. Secondly, am I coding the SignUpForm in forms.py correctly? I did not want to use the User model in models because it would request username and I didn't want my website to ask for a username. Here is my code: models.py from django.db import

Django - form.save() is not creating ModelForm

左心房为你撑大大i 提交于 2020-05-04 05:31:52
问题 In my Django application users send feedback about task. I'm creating this form with ModelForm , and after form.save() my object is not creating and is not uploading to database. Here are my codes: views.py : @login_required(login_url='sign_in') def task_details(request, slug): if slug: task = get_object_or_404(Task, slug=slug) today = datetime.now().date() deadline = task.task_deadline.date() time_left = deadline - today form = CreateFeedbackForm() if request.method == 'POST': form =

Django - form.save() is not creating ModelForm

强颜欢笑 提交于 2020-05-04 05:30:26
问题 In my Django application users send feedback about task. I'm creating this form with ModelForm , and after form.save() my object is not creating and is not uploading to database. Here are my codes: views.py : @login_required(login_url='sign_in') def task_details(request, slug): if slug: task = get_object_or_404(Task, slug=slug) today = datetime.now().date() deadline = task.task_deadline.date() time_left = deadline - today form = CreateFeedbackForm() if request.method == 'POST': form =

Django - form.save() is not creating ModelForm

我怕爱的太早我们不能终老 提交于 2020-05-04 05:29:31
问题 In my Django application users send feedback about task. I'm creating this form with ModelForm , and after form.save() my object is not creating and is not uploading to database. Here are my codes: views.py : @login_required(login_url='sign_in') def task_details(request, slug): if slug: task = get_object_or_404(Task, slug=slug) today = datetime.now().date() deadline = task.task_deadline.date() time_left = deadline - today form = CreateFeedbackForm() if request.method == 'POST': form =

How to override the str method when rendering StackedInline field?

北城余情 提交于 2020-04-30 07:51:28
问题 I have a many to many relationship: class GroupeCategoriesCategorie(models.Model): groupe_categories = models.ForeignKey(GroupeCategories, related_name='groupe', verbose_name=_(u'Groupe')) categorie = models.ForeignKey(Categorie, related_name='categorie', verbose_name=_(u'Catégorie')) def __str__(self): return _(u'{} / {}').format(self.groupe_categories, self.categorie) I always need a representation like the __str__ method before except when rendering in the admin. Why? My admin.py looks

How to override the str method when rendering StackedInline field?

断了今生、忘了曾经 提交于 2020-04-30 07:51:01
问题 I have a many to many relationship: class GroupeCategoriesCategorie(models.Model): groupe_categories = models.ForeignKey(GroupeCategories, related_name='groupe', verbose_name=_(u'Groupe')) categorie = models.ForeignKey(Categorie, related_name='categorie', verbose_name=_(u'Catégorie')) def __str__(self): return _(u'{} / {}').format(self.groupe_categories, self.categorie) I always need a representation like the __str__ method before except when rendering in the admin. Why? My admin.py looks

Django checkout not accessible: Page not found (404)

不打扰是莪最后的温柔 提交于 2020-04-30 06:32:25
问题 I'm trying to develop an e-commerce site with Django. So I'm at this point where, users can add items to their cart, but when I try to proceed to checkout, for some reason, my checkout form is not displayed rather, it says: Page not found (404) I made sure that I have registered my models, and ran migrations. What is the problem? My views.py: @login_required def checkout(request): address_form = UserAddressForm(request.POST or None) if address_form.is_valid(): new_address = address_form.save