django-forms

Override label in Django Forms

こ雲淡風輕ζ 提交于 2020-06-03 09:57:25
问题 I have 3 sections with identical fields, except for label on "title" field. For all of them I'm using same Django Form. In views I have: def get(self): context = self.CONTEXT_CLASS(self.MODEL_CLASS) context.messages = self.get_messages() context.section1 = InvoiceContentForm() context.section2 = InvoiceContentForm() context.section3 = InvoiceContentForm() self.render_jinja('templates/invoice/add_edit.html', context.as_dict) My form: class InvoiceContentForm(forms.Form): """Form for content of

Initialize a formset

笑着哭i 提交于 2020-05-29 07:48:57
问题 I have two models connected by manytomany relationship and I am trying to use formset to create a dynamic form. I am able to save the form but the problem arise when I am trying to edit the saved instance, I don't know how to properly pass the instance to the formset such that it shows the instance data in form for editing Here are the details: Models.py class Player(models.Model): pname = models.CharField(max_length=50) hscore = models.IntegerField() age = models.IntegerField() def __str__

Django cleaned_data.get('obj') method returns none

久未见 提交于 2020-05-27 07:24:46
问题 I'm doing a little password confirmation form in django. But Im confused as the self.cleaned_data.get('confirm_password') always returns none and hence my passwords never match to one another. Heres the clean method in the forms.py def clean_password(self): password = self.cleaned_data.get("password") confirm_password = self.cleaned_data.get("confirm_password") if password != confirm_password: print(password) print(confirm_password) raise forms.ValidationError( "Password and password

Django cleaned_data.get('obj') method returns none

佐手、 提交于 2020-05-27 07:23:49
问题 I'm doing a little password confirmation form in django. But Im confused as the self.cleaned_data.get('confirm_password') always returns none and hence my passwords never match to one another. Heres the clean method in the forms.py def clean_password(self): password = self.cleaned_data.get("password") confirm_password = self.cleaned_data.get("confirm_password") if password != confirm_password: print(password) print(confirm_password) raise forms.ValidationError( "Password and password

Django cleaned_data.get('obj') method returns none

微笑、不失礼 提交于 2020-05-27 07:23:04
问题 I'm doing a little password confirmation form in django. But Im confused as the self.cleaned_data.get('confirm_password') always returns none and hence my passwords never match to one another. Heres the clean method in the forms.py def clean_password(self): password = self.cleaned_data.get("password") confirm_password = self.cleaned_data.get("confirm_password") if password != confirm_password: print(password) print(confirm_password) raise forms.ValidationError( "Password and password

Select item in Django admin inline with radio buttons

谁说胖子不能爱 提交于 2020-05-25 05:45:28
问题 Here's part of my models.py: class Person(models.Model): birth_year = WideYear(null=True, blank=True) birth_year_uncertain = models.BooleanField() death_year = WideYear(null=True, blank=True) death_year_uncertain = models.BooleanField() flourit_year = WideYear(null=True, blank=True) flourit_year_uncertain = models.BooleanField() FLOURIT_CHOICES = ( (u'D', u'Birth and death dates'), (u'F', u'Flourit date'), ) use_flourit = models.CharField('Date(s) to use', max_length=2, choices=FLOURIT

Django - How to make a form for a model's foreign keys?

≯℡__Kan透↙ 提交于 2020-05-25 04:31:50
问题 Here's what I'm trying to do. I'm wondering if someone can suggest a good approach: models.py: class Color(models.Model): name = models.CharField(... class Speed(models.Model): name = models.CharField(... class Dog(models.Model): name = models.CharField(... color = models.ForeignKey(Color... speed = models.ForeignKey(Speed... class DogRequest(models.Model): dog = models.ForeignKey(Dog... request_time = models.DateTimeField() Now I want to have a page where a user can enter or edit a

Django Class based UpdateView with Form for Multiple Uploaded Files

狂风中的少年 提交于 2020-05-24 04:07:04
问题 I have two questions in regards to the problem I am currently facing: Is it best practice in django to overwrite the post method in the CreateView? If it isn't do you write a form _valid function on the CategoryFullForm or in the CreateView and how would it look? The CreateView currently works great, but want to make sure there isn't a better way to do this. If this is best practice, how would you override the get function in the UpdateView so you would be able to edit the files that relate

How to do mapping user input HTML page to view.py in django?

北慕城南 提交于 2020-05-17 09:04:09
问题 I am a newbie in Django and not able to map my user-input to my stored procedure query. views.py from django.db import connection from django.shortcuts import render from .forms import InputForm def home_view(request): print("woooooooooooo",request) context1 ={} context1['form']= InputForm() print("context1::::", context1) return render(request, "input.html", context1) def itemnumber(request): cursor = connection.cursor() try: itemnumber = "23241715" C=cursor.execute(f"EXEC

Django: How to handle error message in CreateView for UNIQUE constraint failed

泪湿孤枕 提交于 2020-05-17 08:46:54
问题 I have a generic class based createview, which generates "UNIQUE constraint failed" error. I am able to handle this and redirect it to the same createview form. However i need to send an error msg to the createview saying 'Name already exists'. How to i achieve this. model.py class Release(models.Model): name = models.CharField(max_length=200, db_index=True) class Feature(models.Model): release = models.ForeignKey(Release, on_delete=models.SET_NULL, null=True, related_name='features') name =