Example #1
0
class ReviewDetailForm(forms.ModelForm):
    """
    Форма выбора полей продукта и юзера в модели комментария
    """
    class Meta:
        model = Review
        exclude = ('', )

    user = fields.AutoCompleteSelectField('users', label='Клиент')
    product = fields.AutoCompleteSelectField(
        'products', label='Товар', help_text="""Введите имя товара.""")
 def test_has_changed(self):
     field = fields.AutoCompleteSelectField('book')
     self.assertFalse(field.has_changed(1, '1'))
     self.assertFalse(field.has_changed('abc', 'abc'))
     self.assertTrue(field.has_changed(1, '2'))
     self.assertFalse(field.has_changed(None, ''))
     self.assertFalse(field.has_changed(None, None))
     self.assertFalse(field.has_changed('', None))
    def test_render_required_field(self):
        field = fields.AutoCompleteSelectField('book', required=True)
        widget = field.widget

        book = Book.objects.create(name='book')
        out = widget.render('book', book.pk)
        self.assertTrue('autocompleteselect' in out)
        self.assertTrue('required' not in out)
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')
Example #5
0
class BasketDetailForm(forms.ModelForm):
    """
    Форма выбора полей продукта и юзера в модели корзины
    """
    class Meta:
        model = Basket
        exclude = ('date_hierarchy', )

    user = fields.AutoCompleteSelectField('users', label='Клиент')
    product = fields.AutoCompleteSelectMultipleField(
        'products', label='Товар', help_text="""Введите имя товара.""")
Example #6
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
Example #7
0
 def get_form_field(self, queryset):
     return ajax_fields.AutoCompleteSelectField("servidores",
                                                required=False,
                                                help_text="",
                                                label=self.title)