django-validation

Custom validation in Django admin

假装没事ソ 提交于 2020-08-21 01:55:09
问题 I have a very simple Django app in order to record the lectures given my colleagues.Since it is quite elementary,I am using the Django admin itself. Here is my models.py: #models.py from django.db import models class Lecture(models.Model): topic = models.CharField(max_length=100) speaker = models.CharField(max_length=100) start_date = models.DateField() end_date = models.DateField() I need to ensure that nobody enters the start date after the end date in the admin forms,so I read the django

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 raise forms.ValidationError not working

不问归期 提交于 2020-01-17 01:36:48
问题 I am trying to add a validator to django model form such that if specific value is selected then other field in the form should be entered if not entered it should give a validation error in the below form if the user selects "Project Support Activities" from the activity_name drop down then the project id field should be mandatory Django Form class ActivityTrackerModelForm(forms.ModelForm): date = forms.DateField(label='', widget=forms.DateInput(attrs={ "placeholder": "Select Date", 'id':

Django ModelChoiceField - use something other than id?

ε祈祈猫儿з 提交于 2020-01-12 07:09:55
问题 Say I have an address table and it has a postal_code field -- ModelChoiceField does not allow me to use something other than PKs to validate existence correct? What would be the way to go? Normal input and use clean_*() ? 回答1: What about to_field_name ? I'm not sure if it's documented anywhere, but you can find it easily between ModelChoiceField constructor params: https://github.com/django/django/blob/master/django/forms/models.py. It is used to filter field queryset. For example: articles =

Django ModelChoiceField - use something other than id?

大城市里の小女人 提交于 2020-01-12 07:09:48
问题 Say I have an address table and it has a postal_code field -- ModelChoiceField does not allow me to use something other than PKs to validate existence correct? What would be the way to go? Normal input and use clean_*() ? 回答1: What about to_field_name ? I'm not sure if it's documented anywhere, but you can find it easily between ModelChoiceField constructor params: https://github.com/django/django/blob/master/django/forms/models.py. It is used to filter field queryset. For example: articles =

Django ModelChoiceField - use something other than id?

天涯浪子 提交于 2020-01-12 07:09:06
问题 Say I have an address table and it has a postal_code field -- ModelChoiceField does not allow me to use something other than PKs to validate existence correct? What would be the way to go? Normal input and use clean_*() ? 回答1: What about to_field_name ? I'm not sure if it's documented anywhere, but you can find it easily between ModelChoiceField constructor params: https://github.com/django/django/blob/master/django/forms/models.py. It is used to filter field queryset. For example: articles =

why does password reset works with unregistered email in django?

半世苍凉 提交于 2020-01-06 04:20:11
问题 I have a couple of questions regarding how the password reset works in Django. How can I do testing on password reset testing during development phase? The password reset sends email to unregistered email addresses successfully (as appears on screen). I thought it should display "no such registered email address is found" instead of displaying "password reset successful". Here is the form used for password reset. I am confused from the form action. It submits to itself which is http://127.0.0

why does password reset works with unregistered email in django?

独自空忆成欢 提交于 2020-01-06 04:20:06
问题 I have a couple of questions regarding how the password reset works in Django. How can I do testing on password reset testing during development phase? The password reset sends email to unregistered email addresses successfully (as appears on screen). I thought it should display "no such registered email address is found" instead of displaying "password reset successful". Here is the form used for password reset. I am confused from the form action. It submits to itself which is http://127.0.0

Django CreateView: set user before validation

删除回忆录丶 提交于 2020-01-02 10:02:05
问题 I have a model that uses different validation for its name field depending on whether the object was created by a user or by the system. class Symbol(models.Model): name = models.CharField(_('name'), unique=True, max_length=64) creator = models.ForeignKey('User', null=True, on_delete=models.CASCADE) def is_system_internal(self): """ whether or not this Symbol belongs to the system rather than having been created by a user """ return (self.creator is None) def clean(self): """ ensure that the

Adding css class to field on validation error in django

回眸只為那壹抹淺笑 提交于 2020-01-01 04:21:06
问题 I am using Django's modelform and its really good. How can I highlight the actual text box (e.g. border:red ) if there is a validation error associated with it. Basically what i want is to add a class (error) if there is a validation error to a field. 回答1: What about defining error_css_class? http://docs.djangoproject.com/en/dev/ref/forms/api/#styling-required-or-erroneous-form-rows? class MyForm(ModelForm): error_css_class = 'error' 回答2: Expanding upon errx's answer. Add the CSS .error input