Found it!
My Post Request is storing the first name that is selected. Now I pass this name into my views. My issue is if I try to put:
{{x.first_name}} {{last.name}}
I could .split()[1] these in my view and just search by the last name. But if a user has the same last name as another I am in trouble.
Any ideas about how to filter for the user_id, so I don’t run into an issue where I am getting the wrong id?
My models where set up like this:
from django.db import models
from django.contrib.auth.models import AbstractUser
#from localflavor.us.models import USStateField
# Create your models here.
class User(AbstractUser):
"""User can be Employee or Customer"""
#state = USStateField()
class Business(models.Model):
business = models.CharField(max_length=50)
class BusinessOwner(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, null=True )
business = models.ForeignKey(Business, on_delete=models.CASCADE, null=True)
class Customer(models.Model):
""" Customer-specific information """
JOB_STATUS =(
("Q", "Quote"),
("R", "Review"),
("W", "Working"),
("C", "Complete"),
)
user = models.OneToOneField(User, on_delete=models.CASCADE, null=True )
business = models.ForeignKey(Business, on_delete=models.CASCADE, null=True)
cust_notes = models.CharField(max_length=1000, blank=True, null=True)
job_status = models.CharField(max_length=10, blank=True,null=True, choices = JOB_STATUS ) #add.update(review = 'R') to change field.
job_name = models.CharField(max_length=500, blank=True, null=True)
note_by = models.CharField(max_length=500, blank=True, null=True)
note_created_at = models.DateTimeField(auto_now_add=True)
note_updated_at = models.DateTimeField(auto_now=True, null=True)
selected_cust = models.CharField(max_length=50, blank=True )
class Employee(models.Model):
""" Employee-specific information """
user = models.OneToOneField(User, on_delete=models.CASCADE, null=True)
business = models.ForeignKey(Business, on_delete=models.CASCADE, null=True, blank=True)
part of my views.py that is applicable
def customer_note(request):
if request.method =="POST":
customer_form = CustomerForm(request.POST)
if customer_form.is_valid():
get_id = customer_form.save(commit=False) # getting first and last name here to do something with it. The Input in my first post is in a Form. and CustomerForm is that form.
full_name = User.objects.filter( Q(id__icontains=get_id))
customer_form.instance.id = full_name.id #This is where I am stuck.