django-forms

Python regex for integer?

别等时光非礼了梦想. 提交于 2020-01-09 09:57:32
问题 I'm learning regex and I would like to use a regular expression in Python to define only integers - whole numbers but not decimals. I could make one that only allows numbers by using \d , but it also allows decimal numbers, which I don't want: price = TextField(_('Price'), [ validators.Regexp('\d', message=_('This is not an integer number, please see the example and try again')), validators.Optional()]) How can I change the code to only allow integers? 回答1: Regexp work on the character base,

Django - ModelForm Create or Update? [duplicate]

南笙酒味 提交于 2020-01-09 09:08:14
问题 This question already has answers here : How to update an object from edit form in Django? (2 answers) Closed 3 years ago . I need to have a form that allows the creation or addition of sessions on a planning Model class Session(models.Model): tutor = models.ForeignKey(User) start_time = models.DateTimeField() end_time = models.DateTimeField() Form class SessionForm(forms.ModelForm): class Meta: model = Session exclude = ['tutor'] View to render the form def editor(request): if request.method

Django - ModelForm Create or Update? [duplicate]

被刻印的时光 ゝ 提交于 2020-01-09 09:07:27
问题 This question already has answers here : How to update an object from edit form in Django? (2 answers) Closed 3 years ago . I need to have a form that allows the creation or addition of sessions on a planning Model class Session(models.Model): tutor = models.ForeignKey(User) start_time = models.DateTimeField() end_time = models.DateTimeField() Form class SessionForm(forms.ModelForm): class Meta: model = Session exclude = ['tutor'] View to render the form def editor(request): if request.method

Django - ModelForm Create or Update? [duplicate]

纵饮孤独 提交于 2020-01-09 09:03:24
问题 This question already has answers here : How to update an object from edit form in Django? (2 answers) Closed 3 years ago . I need to have a form that allows the creation or addition of sessions on a planning Model class Session(models.Model): tutor = models.ForeignKey(User) start_time = models.DateTimeField() end_time = models.DateTimeField() Form class SessionForm(forms.ModelForm): class Meta: model = Session exclude = ['tutor'] View to render the form def editor(request): if request.method

Why executing form.is_valid() cause deleting of the instance fields that aren't in the form in django?

一笑奈何 提交于 2020-01-07 09:24:03
问题 Suppose this view that is for edit record: def edit_post(request, slug): post = get_object_or_404(Post, slug=slug) if request.method == "POST": form = AddPostForm(request.POST, request.FILES, instance=post) # 1 if form.is_valid(): # 2 new_post = form.save(commit=False) new_post.save() return redirect('administrator:view_admin_post') ... Now assume these: I have field1 that is exist in POST model. field1 has default value and suppose that the current value of field1 depends on previous. Also

Django Model Form Many to Many field is not displaying value

巧了我就是萌 提交于 2020-01-07 09:05:32
问题 I have a many to many field and a foreign key field on a model form. It appears to be making the right query but the result are Objects and not the values of the object. Do I need to overwrite the queryset using a VALUES_LIST method? forms.py class Meta: model = AccountParameters fields =['acctFilterName', 'excludeClassification', 'tradingCash',] #exclude = ['acctFilterName'] labels = { 'acctFilterName': _('Account Filters:'), 'excludeClassification': _('Exclude Classifications: '),

error while submitting data in the form django

风流意气都作罢 提交于 2020-01-07 04:48:24
问题 I am trying to insert data into db it throws below error,can any please fix this. enter code here model.py from django.db import models # Create your models here. class Profile(models.Model): name = models.CharField(max_length=50, primary_key=True) assign = models.CharField(max_length=50) doj = models.DateField() class Meta: db_table= 'profile' def __unicode__(self): return u'%s' % (self.name) class working(models.Model): w_name =models.ForeignKey(Profile, db_column='w_name') monday = models

Jquery function not defined with onclick attribute set inside django forms (forms.py)

好久不见. 提交于 2020-01-07 04:40:11
问题 I have a django form with onclick attribute set to a jQuery function located inside a .JS file and I want that function to be called whenever the onclick event is triggered . When I click on the form , it says my function is not defined . Maybe the answer is easy and obvious but I'm kind of newbie in both jQuery and Django .I have googled it around but still can't work this out . Any help would be great . forms.py class UserProfileForm(forms.ModelForm): class Meta: model = Profile fields = (

Save m2m in FormView django

无人久伴 提交于 2020-01-07 04:22:07
问题 I'm trying to save a m2m field in a FormView . Here is my code: class ProductorPropietarioView(FormView): form_class = FormPropietario success_url = '/' template_name = 'productores/propietario.html' def form_valid(self,form): form.save(commit=False) form.save() form.save_m2m() return super(ProductorPropietarioView,self).form_valid(form) models.py class Persona(models.Model): predio = models.ForeignKey(InfoPredioGeneral,related_name='predio+') rol = models.ManyToManyField(RolPersona) tipo

FormView CBV change ModelForm per request

自闭症网瘾萝莉.ら 提交于 2020-01-07 01:59:44
问题 I am trying to build a Wizard for populating data in to DataBase. I try the session.Wizard with out success plus I don't think this is what ti need. correct me if I am wrong. so basically my database have some tables which needs to be fill, because of the joints need to be done, I wanted to make a nice wizard which takes you along the way. so I have a base template which would have steps, sometimes there would be no need in creating a new data if exists all ready. so I have made a display of