Wednesday, October 28, 2020

Filter a field in a form CreatView

Hi guys, How r u doing?

I have a field called articulos that is foreign key,  in a form is defined as follow:
from django import forms
#from django.contrib.auth.models import User
from .models import Stockmov

class StockmovForm(forms.ModelForm):
    class Meta:
        model = Stockmov
        #fields ="__all__"
        fields =  ['articulo', 'motivo', 'Cantidad' ]
        widgets = {
        'articulo': forms.Select(attrs={'class':'form-control', 'placeholder':'Articulo'}),
        'motivo': forms.TextInput(attrs={'class':'form-control', 'placeholder':'Motivo'}),
        'Cantidad': forms.NumberInput(attrs={'class':'form-control', 'placeholder':'Cantidad'}),
        labels = {
            'articulo':'', 'motivo':'', 'Cantidad':'',

I want to allow the user to search an instance in the same  combobox articulo in the createview. Check the pic.

Whats is the best native way to do that?Other alternatives?

Thanks in Advance!

You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit

No comments:

Post a Comment