django-forms

Override Django ImageField validation

☆樱花仙子☆ 提交于 2020-01-16 00:48:11
问题 I am trying to create a form where users will be allowed to upload any image file + SWF files. Django's ImageField does not support SWF so I need to override it. What I want to do is to check if the file is SWF, if True, return it. If it's not SWF, call the original method which will take care of the file validation. However, I am not sure how to implement that. Here is an example of what I am trying to achieve, but it does not work: from hexagonit import swfheader class SwfImageField(forms

Django: why the manytomany choice box only has on side

社会主义新天地 提交于 2020-01-15 20:11:57
问题 I have extended the group model, where I added some manytomany fields, and in the admin page, it likes this: However, what I expected is this: Here is how I implemented the m2m field: class MyGroup(ProfileGroup): mobile = models.CharField(max_length = 15) email = models.CharField(max_length = 15) c_annotates = models.ManyToManyField(Annotation, verbose_name=_('annotation'), blank=True, null=True) c_locations = models.ManyToManyField(Location, verbose_name=_('locations'), blank=True, null=True

Django custom error message

爷,独闯天下 提交于 2020-01-15 09:32:29
问题 I want to display error messages in my native language. Below pasted code from 4 different trials and none of them worked None of the methods I found were not working Django, Models & Forms: replace "This field is required" message forms.py class UserCreateForm(UserCreationForm): email = forms.EmailField(required=True, error_messages = {'required': "custom"}) first_name = forms.CharField(required=True) last_name = forms.CharField(required=True) class Meta: model = User fields = ("username",

Django custom error message

青春壹個敷衍的年華 提交于 2020-01-15 09:32:12
问题 I want to display error messages in my native language. Below pasted code from 4 different trials and none of them worked None of the methods I found were not working Django, Models & Forms: replace "This field is required" message forms.py class UserCreateForm(UserCreationForm): email = forms.EmailField(required=True, error_messages = {'required': "custom"}) first_name = forms.CharField(required=True) last_name = forms.CharField(required=True) class Meta: model = User fields = ("username",

Django custom error message

坚强是说给别人听的谎言 提交于 2020-01-15 09:32:05
问题 I want to display error messages in my native language. Below pasted code from 4 different trials and none of them worked None of the methods I found were not working Django, Models & Forms: replace "This field is required" message forms.py class UserCreateForm(UserCreationForm): email = forms.EmailField(required=True, error_messages = {'required': "custom"}) first_name = forms.CharField(required=True) last_name = forms.CharField(required=True) class Meta: model = User fields = ("username",

Django multiple annotate slows down the query

自古美人都是妖i 提交于 2020-01-15 03:59:29
问题 I have been debugging with django debug_toolbar , if I use more than one annotate in query then it takes a lot of time for Django to fetch the query results. class Project_First(models.Model): project_first_results_M2M = models.ManyToManyField(Project_First_Results) class Project_Second(models.Model): project_second_results_M2M = models.ManyToManyField(Project_Second_Results) class Project(models.Model): project_first_M2M = models.ManyToManyField(Project_First) project_second_M2M = models

Django multiple annotate slows down the query

你离开我真会死。 提交于 2020-01-15 03:59:07
问题 I have been debugging with django debug_toolbar , if I use more than one annotate in query then it takes a lot of time for Django to fetch the query results. class Project_First(models.Model): project_first_results_M2M = models.ManyToManyField(Project_First_Results) class Project_Second(models.Model): project_second_results_M2M = models.ManyToManyField(Project_Second_Results) class Project(models.Model): project_first_M2M = models.ManyToManyField(Project_First) project_second_M2M = models

Django 1.9 URLField removing the necessary http:// prefix

流过昼夜 提交于 2020-01-15 03:41:29
问题 I've seen a bunch of questions about this, but havent found an answer yet. This is my models: class UserProfile(models.Model): user = models.OneToOneField(User) . . . website = models.URLField(max_length=100, blank=True, null=True) and my forms.py: class UserProfileForm(forms.ModelForm): class Meta: model = UserProfile fields = ('website') def clean_website(self): website = self.cleaned_data['website'] if website and not website.startswith('http://'): website = 'http://' + website return

Migrating Django from 1.9 to 1.11: trouble with MultiValueField and MultiWidget behaviour

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-15 01:51:18
问题 Here is a code that works as expected in Django 1.9: class MultipleBooleanField(forms.MultiValueField): def __init__(self, *args, **kwargs): self.fieldnames = kwargs.pop('fields') fields = [ forms.BooleanField(required=False) for x in self.fieldnames ] super(MultipleBooleanField, self).__init__(fields=fields, require_all_fields=False, *args, **kwargs) self.widget = MultipleBooleanWidget(widgets=[ f.widget for f in fields ]) self.widget.fieldnames = self.fieldnames def compress(self, datalist)

django smart selects on Django version 3.0.1 - error ImportError: cannot import name 'six' from 'django.utils'

旧城冷巷雨未停 提交于 2020-01-15 01:48:47
问题 Installed django-smart-selects (pip install django-smart-selects) and is not working on django version 3.0.1 I configured using the official installation guide. enter code here $ python manage.py runserver Watching for file changes with StatReloader Exception in thread django-main-thread: Traceback (most recent call last): File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner self.run() File "/usr/lib/python3.7/threading.py", line 865, in run self._target(*self._args, **self.