class AgregarProducto(forms.ModelForm):
class Meta:
model = productos
def __init__(self, *args, **kwargs):
user = kwargs.pop('user')
super(AgregarProducto, self).__init__(*args, **kwargs)
self.fields['secciones'].queryset = secciones.objects.filter(user=user)
if request.method == "POST":
modelform = AgregarProducto(request.POST, request.FILES, user=request.user)
...
else:
modelform = AgregarProducto(user=request.user)
from django.contrib.auth.decorators import login_required
@login_required
def agregar_producto(request):