def create(self): """ check customers plan and limit them to the number of website that's accordigng to their plan""" "check customers plan, check customers website count" if re.match(self.pattern, self.url, flags=0): try: customer = Customer.get(id=self.customer) except DoesNotExist: return {"message": "Customer does not exist"} website_count = Website.select().where( Website.customer == customer.id).count() if customer.plan.quantity != 0 and customer.plan.quantity > website_count and customer.renewal_date != None: website = Website(url=self.url, customer=self.customer) website.save() message = "Website created successfully" return {"message": message} if customer.plan.quantity == 0 and customer.renewal_date != None: website = Website(url=self.url, customer=self.customer) website.save() message = "Website created successfully" return {"message": message} if customer.renewal_date == None: return {"message": "Sorry, your plan has expired"} else: return { "message": "Sorry, you can't add more websites, your have exceeded your subscription limit" } else: return {"message": "Invalid website"}