N
N
NikClik2018-06-14 17:21:54
Django
NikClik, 2018-06-14 17:21:54

The ban on adding until another model is filled, how?

I have 3 models, Company, CompanyNews, CompanyGoods
I need to make it so that one user can add only one (!) Record to the Company model and while there is no record in Company from the user, prohibit him from adding records to CompanyNews and CompanyGoods , please tell me how do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Leonid, 2018-06-15
@stilet69

I think it is necessary to check if the Company is full in the CreateView CompanyNews and CompanyGoods methods, for example:
company = Company.objects.filter(user = self.user)
if there is one entry in the QuerySet company, then we continue, if the value is empty, then we issue a message or redirect to the page, where it is explained to him that he needs to create a Company.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question