I have some models classes. And some classes have bounding fields with another class. Each class have the field - author. I whould like that for each user the form bounding field shows only those data which was created these authors.
For example:
class "TypeJob" has field "author".
User Jhon created a TypJob - "Painting".
User Alex created a TypJob - "Cleaning".
Class "Order" has bounding field - "name_typ_job"
When Jhon whould like create an order, he opens the form and click "name type job" field, he sees both type job: painting and cleaning.
I whould like that he sees and could choose only "painting". Because he is it author.
I wrote that
class OrderTestForm(forms.ModelForm): class Meta: model = Order name_job = forms.ModelChoiceField(queryset=None) qs = TypJob.objects.filter(author__id=user.id) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields['name_job'].queryset = qs
But I have
name 'user' is not defined
name 'author__id' is not defined
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 django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/178dcdb1-c119-46ef-83c3-95bda19118c8%40googlegroups.com.
No comments:
Post a Comment