django-forms

how to check if a string fullfil with multiple regex and capture that portion that match?

五迷三道 提交于 2019-12-20 03:55:13
问题 What I want I'm working with a django form and it takes a password input. I need to pass the input value for multiple regexes, which will test if: at least one character is a lowecase at least one character is a uppercase at least one character is a number at least one character is a especial character (symbol) 8 characters minimum And I would like to know which of these conditions were fulfilled and which were not. What I've done def clean_password(self): password = self.cleaned_data.get(

Extend django-import-export's import form to specify fixed value for each imported row

拜拜、爱过 提交于 2019-12-20 03:13:58
问题 I am using django-import-export 1.0.1 with admin integration in Django 2.1.1. I have two models from django.db import models class Sector(models.Model): code = models.CharField(max_length=30, primary_key=True) class Location(models.Model): code = models.CharField(max_length=30, primary_key=True) sector = ForeignKey(Sector, on_delete=models.CASCADE, related_name='locations') and they can be imported/exported just fine using model resources from import_export import resources from import_export

Django inlineformset_factory and ManyToMany fields

六月ゝ 毕业季﹏ 提交于 2019-12-20 01:38:23
问题 I'm attempting to create a formset for the following models: class Category(models.Model): name = models.CharField(max_length=100, unique=True) description = models.TextField(null = True, blank=True) class Recipe(models.Model): title = models.CharField(max_length=100) body = models.TextField() user = models.ForeignKey(User) categories = models.ManyToManyField(Category, null = True, blank = True) But any time I try to implement a formset, like so: FormSet = inlineformset_factory(Category,

Django: customizing the message after a successful form save

被刻印的时光 ゝ 提交于 2019-12-19 19:52:53
问题 whenever I save a model in my Admin interface, it displays the usual "successfully saved message." However, I want to know if it's possible to customize this message because I have a situation where I want to warn the user about what he just saved and the implications of these actions. class PlanInlineFormset(forms.models.BaseInlineFormset): def clean(self): ### How can I detect the changes? ### (self.changed_data doesn't work because it's an inline) ### and display what he/she just changed

Encode Base64 Django ImageField Stream

拟墨画扇 提交于 2019-12-19 19:52:31
问题 I receive an Image through my form, which I not want to save as usual in a FileField but in a CharField as Base64. This is my current setup: models.py class Image(models.Model): company = models.ForeignKey(Company) img = models.TextField() img_id = models.CharField(blank=True, null=True, max_length=64) img_class = models.CharField(blank=True, null=True, max_length=64) created = models.DateField(auto_now_add=True, editable=False) forms.py class ImageForm(forms.Form): img = forms.ImageField()

Set form field value before is_valid()

只愿长相守 提交于 2019-12-19 16:37:29
问题 I'm having a bit of trouble grasping how to do this. I've put my best effort into searching Google without any luck. I'll start with a bit of code and explain what I'm trying to do as I go: models.py class Action(models.Model): title = models.CharField(max_length=200) owner = models.ForeignKey(User, related_name='actions') created_by = models.ForeignKey(User, related_name='+', editable=False) modified_by = models.ForeignKey(User, related_name='+', editable=False) class ActionForm(ModelForm):

Django Templates: Form field name as variable?

我的未来我决定 提交于 2019-12-19 11:21:10
问题 How can I make this loop to print form fields where XXXXXXXX is the value of ticket.id? {% for ticket in zone.tickets %} {{ ticket.id }}: {{ form.ticket_count_XXXXXXXX }} {% endfor %} So the output to be something like this... 1: <input ... name="ticket_count_1"> 10: <input ... name="ticket_count_10"> 12: <input ... name="ticket_count_12"> 3: <input ... name="ticket_count_3"> 回答1: You can't pass arguments in the django template, so no. You'd need to implement a template tag (more of a pain)

Django: How to create form with ForeignKey field (input as CharField)

本秂侑毒 提交于 2019-12-19 10:44:23
问题 I have created two models Article and Author as this: model.py class Article(models.Model): title = models.CharField(max_length=200) content = models.TextField(max_length = 5000) author = models.ForeignKey('Author', on_delete=models.CASCADE) class Author(models.Model): author_name = models.CharField(max_length=200) author_intro = models.TextField(max_length = 3000) And I am trying to create a form that lets user input Article information *(including title, content, author only). So that

Override defaults attributes of a Django form

丶灬走出姿态 提交于 2019-12-19 09:44:16
问题 In my Django app I have several different forms, which are similar in style. To not repeat myself over and over again, I try to rewrite the default form settings. As a start I wanted to set some default settings for every form I use in my app and tried to subclass the django.forms.Form : class DefaultForm(forms.Form): error_css_class = 'alert' error_class = DivErrorList required_css_class = 'required' label_suffix = ':' auto_id = True class TechnicalSurveyForm(DefaultForm): location = forms

How do you change the order of Django's SelectDateWidget to day, month, year?

最后都变了- 提交于 2019-12-19 08:21:12
问题 This is the form: from django.forms.extras.widgets import SelectDateWidget class EntryForm(forms.ModelForm): class Meta(): model = Entry def __init__(self, *args, **kwargs): super(EntryForm, self).__init__(*args, **kwargs) this_year = datetime.date.today().year years = range(this_year-100, this_year+1) years.reverse() self.fields["date_of_birth"].widget = SelectDateWidget(years=years) The date of birth field is rendered like so How do I change it so that it will render as day, month, year?