I want an app, to manage my clients. Save and sort ba name with addresse, contact person and his datas, with shot blasting machine type of the customer and used media for the machine. after it I need a site to be able to create notes for the clients I saved before.
To upload files, please first save the app
import streamlit as st
from sqlalchemy import create_engine, Column, Integer, String, ForeignKey, Text, DateTime
from sqlalchemy.orm import Session, relationship
from sqlalchemy.orm import DeclarativeBase
import datetime
# Database setup
class Base(DeclarativeBase):
pass
class Client(Base):
__tablename__ = 'clients'
id = Column(Integer, primary_key=True)
name = Column(String(100), nullable=False)
address = Column(String(200))
contact_person = Column(String(100))
contact_email = Column(String(100))
contact_phone = Column(String(20))
machine_type = Column(String(100))
media_type = Column(String(100))
notes = relationship("Note", back_populates="client")
class Note(Base):
__tablename__ = 'notes'
id = Column(Integer, primary_key=True)
client_id = Column(Integer, ForeignKey('clients.id'))
content = Column(Text, nullable=False)
created_at = Column(DateTime, default=datetime.datetime.utcnow)
client = relationship("Client", back_populates="notes")
# Create database engine
engine = create_engine('sqlite:///clients.sqlite')
Base.metadata.create_all(engine)
# Streamlit app
st.title('Client Management System')
# Sidebar navigation
page = st.sidebar.radio("Navigate to", ["Manage Clients", "Client Notes"])
if page == "Manage Clients":
st.header("Client Management")
# Form for adding/editing clients
with st.form("client_form"):
client_name = st.text_input("Client Name")
address = st.text_input("Address")
contact_person = st.text_input("Contact Person")
contact_email = st.text_input("Email")
contact_phone = st.text_input("Phone")
machine_type = st.text_input("Shot Blasting Machine Type")
media_type = st.text_input("Media Type")
submit_button = st.form_submit_button("Save Client")
if submit_button and client_name:
with Session(engine) as session:
new_client = Client(
name=client_name,
address=address,
contact_person=contact_person,
contact_email=contact_email,
contact_phone=contact_phone,
machine_type=machine_type,
media_type=media_type
)
session.add(new_client)
session.commit()
st.success("Client saved successfully!")
# Display clients
with Session(engine) as session:
clients = session.query(Client).order_by(Client.name).all()
if clients:
st.subheader("Client List")
for client in clients:
with st.expander(f"{client.name}"):
st.write(f"Address: {client.address}")
st.write(f"Contact Person: {client.contact_person}")
st.write(f"Email: {client.contact_email}")
st.write(f"Phone: {client.contact_phone}")
st.write(f"Machine Type: {client.machine_type}")
st.write(f"Media Type: {client.media_type}")
elif page == "Client Notes":
st.header("Client Notes")
# Get client list for selection
with Session(engine) as session:
clients = session.query(Client).order_by(Client.name).all()
client_names = [client.name for client in clients]
if not clients:
st.warning("No clients found. Please add clients first.")
else:
selected_client_name = st.selectbox("Select Client", client_names)
# Get selected client
with Session(engine) as session:
selected_client = session.query(Client).filter_by(name=selected_client_name).first()
# Add new note
with st.form("note_form"):
note_content = st.text_area("New Note")
submit_note = st.form_submit_button("Add Note")
if submit_note and note_content:
new_note = Note(
client_id=selected_client.id,
content=note_content
)
session.add(new_note)
session.commit()
st.success("Note added successfully!")
# Display existing notes
notes = session.query(Note).filter_by(client_id=selected_client.id).order_by(Note.created_at.desc()).all()
if notes:
st.subheader("Previous Notes")
for note in notes:
with st.expander(f"Note from {note.created_at.strftime('%Y-%m-%d %H:%M')}"):
st.write(note.content)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?