Controller Method

while doing some changes in library_member.py


from frappe.model.document import Document

class LibraryMember(Document):
def before_save(self):
self.full_name = {self.first_name} , {self.last_name or “”}

cannot resolve the import statement for frappe.model.document

@akshay2 please uncomment import frappe

Hey @akshay2 , this is actually just a configuration of VS Code that is missing.

On the bottom right corner of the window, there should be a version number for Python. By default this is the Python version of the Operating System, but Frappe uses its own version in its virtual environment.

Click that button “3.X.Y”

Click “Enter interpreter path”

Click “Find…”

Select the “python” file (or “python3” it’s the same).

I think the correct code should look like this:

from frappe.model.document import Document

class LibraryMember(Document):
    def before_save(self):
        self.full_name = f"{self.first_name or ''}, {self.last_name or ''}"

This is using a format string (f-string) for the full_name.

1 Like

thanks now its working properly