コード例 #1
0
class BookForm(ModelForm):
    class Meta:
        model = Book
        fields = ['name', 'author', 'mentions_persons']

    name = fields.AutoCompleteField('name')
    author = fields.AutoCompleteSelectField('author')
    mentions_persons = fields.AutoCompleteSelectMultipleField('person')
コード例 #2
0
class BasketDetailForm(forms.ModelForm):
    """
    Форма выбора полей продукта и юзера в модели корзины
    """
    class Meta:
        model = Basket
        exclude = ('date_hierarchy', )

    user = fields.AutoCompleteSelectField('users', label='Клиент')
    product = fields.AutoCompleteSelectMultipleField(
        'products', label='Товар', help_text="""Введите имя товара.""")
コード例 #3
0
class UserOrderForm(forms.ModelForm):
    """
    Форма выбора поля user в модели Order
    """
    class Meta:
        model = Order
        exclude = ('', )

    user = fields.AutoCompleteSelectField('users', label='Клиент')
    product = fields.AutoCompleteSelectMultipleField(
        'products', label='Товар', help_text="""Введите имя товара.""")
    quantity = forms.IntegerField(label='Кол-во товара')

    def __init__(self, *args, **kwargs):
        """dander __init__ redefined for set initial param for attribute quantity"""
        super().__init__(*args, **kwargs)
        instance: Order = kwargs.get('instance')
        if isinstance(instance, self._meta.model):
            self.initial['quantity'] = OrderDetails.objects.filter(
                order_id=instance.pk).only(
                    'quantity').order_by().first().quantity
コード例 #4
0
 def test_has_changed_blank_input(self):
     field = fields.AutoCompleteSelectMultipleField('book')
     self.assertTrue(field.has_changed(None, ['1']))
     self.assertFalse(field.has_changed(None, []))
コード例 #5
0
 def test_has_changed(self):
     field = fields.AutoCompleteSelectMultipleField('book')
     self.assertFalse(field.has_changed([1], ['1']))
     self.assertFalse(field.has_changed(['abc'], ['abc']))
     self.assertTrue(field.has_changed([1], ['2']))