How to take array of foreign keys in django model - django

I have a model product , price and custorder. I want a list of products while creating the order which is used as a foreign key in custorder. I am using postgres as database.
class Product(models.Model):
product = ArrayField(models.CharField(max_length=200), blank=True)
def __str__(self):
return str(self.product)
class Price(models.Model):
product = models.ForeignKey(Product, on_delete=models.CASCADE)
price = models.DecimalField(max_digits=50, decimal_places = 5, default=0)
def __str__(self):
return "%s" % self.price
class CustOrder(models.Model):
Customer_id = models.AutoField(primary_key=True)
CustomerName = models.CharField(max_length=200)
email = models.EmailField(max_length=70,blank=True, null= True, unique= True)
gender = models.CharField(max_length=6, choices=GENDER_CHOICES)
phone = PhoneField(null=False, blank=True, unique=True)
landmark = models.PointField()
#landmark = models.TextField(max_length=400, help_text="Enter the landmark", default='Enter landmark')
houseno = models.IntegerField(default=0)
#product_name = models.CharField(max_length=200, choices=PRODUCT_CHOICES,default='Boneless chicken')
product = models.ForeignKey(Product, on_delete=models.SET_NULL, null=True,related_name='pricetag')
quantity = models.IntegerField(default=0)
price = models.ForeignKey(Price, on_delete=models.SET_NULL, null=True,related_name='pricetag')
#price = models.DecimalField(max_digits=50, decimal_places=5, default=48.9)
pay_method = models.CharField(max_length=200,choices=PAYMENT_CHOICES, default='RAZOR PAY')
city = models.ForeignKey(City, on_delete=models.SET_NULL, null=True)
area = models.ForeignKey(Area, on_delete=models.SET_NULL, null=True)
Price.objects.aggregate(Sum('price'))
def __str__(self):
return self.CustomerName

Related

I want to assign a user to my card from the User table, but its not working for me

The error is:
django.db.utils.ProgrammingError: column
user_awaycardholder.assigned_user_id does not exist LINE 1:
...der"."id", "user_awaycardholder"."display_id_id", "user_away...
I am not able to create AwayCardHolder can you please tell me what is the above error ??? and How to fix that ?
class UserData(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
title = models.CharField(max_length=40, default="")
phone = models.CharField(max_length=15)
facebook_id = models.CharField(max_length=400)
youtube_id = models.CharField(max_length=400)
linkedin_id = models.CharField(max_length=400)
instagram_id = models.CharField(max_length=400)
twitter_id = models.CharField(max_length=400)
logo = models.ImageField(upload_to='logo')
profile_image = models.ImageField(upload_to='media/profile')
location = models.CharField(max_length=400)
website = models.CharField(max_length=100)
messanger = models.CharField(max_length=200)
parent_id = models.CharField(max_length=20, blank=True)
is_child = models.BooleanField(default=False)
phone_office = models.CharField(max_length=15, blank=True)
hits = models.IntegerField(max_length=10, default=0)
class Meta:
verbose_name_plural = "User Data"
def __str__(self):
name = self.user.first_name + ' ' + str(self.user.id)
return str(name)
class AwayCard(models.Model):
Away_id = models.UUIDField(default=uuid.uuid4, editable=True)
my_admin = models.ForeignKey(User, on_delete=models.CASCADE)
display_id = models.CharField(default='', max_length=30)
is_assigned = models.BooleanField(default=False)
def __str__(self):
name = str(self.display_id)
return str(name)
class AwayCardHolder(models.Model):
display_id = models.OneToOneField(AwayCard, on_delete=models.CASCADE)
assigned_user = models.ForeignKey(User, related_name="user_awaycardholder", on_delete=models.CASCADE)
def __str__(self):
name = self.display_id
return str(name)

Return all the orderitems in an order of a customer Django

I want to return all the items in all the orders that have made a customer.
I don't know if it is possible or how I need to do it, I tried to get the orders with .get and .filter in my views but with get is only possible to return one value
My models.py
class Customer(models.Model):
user = models.OneToOneField(Account, on_delete=models.CASCADE, null=True)
first_name = models.CharField(max_length=200, null=True)
last_name = models.CharField(max_length=200, null=True, blank=True)
phone = models.CharField(max_length=10, null=True, blank=True)
email = models.EmailField(null=True, blank=True)
date_created = models.DateTimeField(auto_now_add=True, null=True)
def __str__(self):
return str(self.user)
class Category(models.Model):
name = models.CharField(max_length=200, null=True)
class Meta:
verbose_name='categoria'
verbose_name_plural ='categorias'
def __str__(self):
return self.name
class Product(models.Model):
name = models.CharField(max_length=200, null=True)
price = models.FloatField(null=True)
category = models.ForeignKey(Category, on_delete=models.SET_NULL, null=True, blank=True)
description = models.TextField(max_length=500, null=True, blank=True)
date_created = models.DateTimeField(auto_now_add=True, null=True)
ventas = models.IntegerField(null=True, blank=True, default=0)
image = models.ImageField(null=True, blank=True, default='Banner_Cubrebocas.png')
def __str__(self):
return self.name
class Order(models.Model):
STATUS= (
('Pending', 'Pending'),
('Delivered', 'Delivered')
)
customer = models.ForeignKey(Customer, on_delete=models.SET_NULL, null=True)
#product = models.ForeignKey(Product, on_delete=models.SET_NULL, null=True, blank=True)
date_created =models.DateTimeField(auto_now_add=True, null=True)
status = models.CharField(max_length=200, null=True, choices=STATUS, default='Pending')
complete = models.BooleanField(default=False, null=True, blank=True)
def __str__(self):
return str(self.id)
#property
def shipping(self):
shipping= False
orderitems=self.orderitem_set.all()
for i in orderitems:
if i.product.digital == False:
shipping=True
return shipping
#property
def get_cart_total(self):
orderitems= self.orderitem_set.all()
total= sum([item.get_total for item in orderitems])
return total
#property
def get_cart_items(self):
orderitems= self.orderitem_set.all()
total= sum([item.quantity for item in orderitems])
return total
class OrderItem(models.Model):
product= models.ForeignKey(Product, on_delete=models.SET_NULL, null=True)
order= models.ForeignKey(Order, on_delete=models.CASCADE, null=True)
quantity= models.IntegerField(default=0, null=True, blank=True)
date_added= models.DateTimeField(auto_now=True, null=True)
and my views.py I tried with different foms but I don't get the correct one
def customer(request, pk_test):
qs = Product.objects.all()
category_query = request.GET.get('category')
status_query = request.GET.get('status')
customer = Customer.objects.get(id=pk_test)
orders= customer.order_set.all()
orders_count = orders.count()
order = Order.objects.filter(customer__id=pk_test, complete=False)
items = order.orderitem_set.all()
#myFilter= OrderFilter(request.GET, queryset=orders)
#orders = myFilter.qs
categories = Category.objects.all()
if status_query != '' and status_query is not None:
items = items.filter(order__status__icontains=status_query)
if status_query == 'All status':
items = order.orderitem_set.all()
context = {
'customer':customer,
'orders':orders,
'orders_count':orders_count,
#'myFilter':myFilter,
'categories':categories,
'order':order,
'items':items,
}
return render(request, 'cuentas/customer.html', context)

Many To Many NOT saving in django

my views.py file:
form = ClassesForm(request.POST)
if form.is_valid():
New_Class = Classes()
New_Class.semester = Last_Semester
New_Class.year = form.cleaned_data.get('year')
if form.cleaned_data.get('year') >= 6 and form.cleaned_data.get('year') <= 8:
New_Class.school_mode = 1
else:
New_Class.school_mode = 2
New_Class.brunch = form.cleaned_data.get('brunch')
New_Class.subject = form.cleaned_data.get('subject')
New_Class.teacher.set(Staff.objects.filter(uuid=form.cleaned_data.get('teacher').uuid))
New_Class.save()
my models.py file:
#reversion.register()
class Classes(BaseModel):
semester = models.ForeignKey(Semester, on_delete=models.PROTECT,default=get_last_semester, verbose_name=("Semester"))
school_mode = models.IntegerField(db_index=True, choices=SCHOOL_MODE, verbose_name=("School Type"))
year = models.IntegerField(db_index=True, choices=CLASS_YEARS, verbose_name=("Year"))
brunch = models.CharField(max_length=2, verbose_name=("Class Brunch"))
subject = models.CharField(max_length=15, choices=CLASS_SUBJECTS, verbose_name=("Subject"))
**teacher = models.ManyToManyField(Staff, blank=True, verbose_name=("Class Teachers"))**
class Meta:
unique_together = ('semester', 'year', 'brunch')
ordering = ['semester', 'year', 'brunch', 'subject']
def __unicode__(self):
return "%d %s %s %s / %s" % (self.semester, self.year, self.brunch, self.subject)
auditlog.register(Classes)
#reversion.register()
class Staff(BaseModel):
photo = models.ImageField(upload_to="Staff/", null=True, blank=True, verbose_name=("Photo"))
user = models.OneToOneField(User, on_delete=models.PROTECT, db_index=True, verbose_name=("User"))
name = models.CharField(max_length=30, db_index=True, verbose_name=("Name"))
surname = models.CharField(max_length=30, db_index=True, verbose_name=("Surname"))
id_no = models.CharField(max_length=15, unique=True,verbose_name=("ID Card Number"))
birthdate = models.DateField(verbose_name=("Birthdate"))
birthplace = models.CharField(max_length=30, verbose_name=("Birthplace"))
gender = models.IntegerField(choices=GENDERS, default=None, verbose_name=("Gender"))
nationality = models.CharField(choices=NATIONALITIES, max_length=20, verbose_name=("Nationality"))
blood_type = models.CharField(choices=BLOOD_TYPES, null=True, blank=True, max_length=10, verbose_name=("Blood Type"))
phone_home = models.CharField(max_length=15, null=True, blank=True, verbose_name=("Phone Home"))
phone_mobile = models.CharField(max_length=15, null=True, blank=True, verbose_name=("Phone Mobile"))
email = models.EmailField(default=None, null=True, blank=True, verbose_name=("Email Address"))
address = models.TextField(verbose_name=("Address"))
brunch = models.ForeignKey(TeacherBrunch, on_delete=models.PROTECT, verbose_name=("Brunch"))
staff_type = models.ManyToManyField(StaffType, verbose_name=("Staff Type"))
staff_status = models.IntegerField(choices=STAFF_STATUS, default=1, verbose_name=("Staff Status"))
additional_information = models.CharField(max_length=100, null=True, blank=True, verbose_name=("Additional Information"))
class Meta:
ordering = ['name', 'surname']
def __unicode__(self):
return "%s %s" % (self.name, self.surname)
def save(self, *args, **kwargs):
self.name = self.name.title()
self.surname = self.surname.upper()
self.user.save()
super(Staff, self).save(*args, **kwargs)
my views.py file:
form = ClassesForm(request.POST)
if form.is_valid():
New_Class = Classes()
New_Class.semester = Last_Semester
New_Class.year = form.cleaned_data.get('year')
if form.cleaned_data.get('year') >= 6 and form.cleaned_data.get('year') <= 8:
New_Class.school_mode = 1
else:
New_Class.school_mode = 2
New_Class.brunch = form.cleaned_data.get('brunch')
New_Class.subject = form.cleaned_data.get('subject')
New_Class.teacher.set(Staff.objects.filter(uuid=form.cleaned_data.get('teacher').uuid))
New_Class.save()
return redirect(reverse('Create-Classes'))
my model.py
class Classes(BaseModel):
semester = models.ForeignKey(Semester, on_delete=models.PROTECT,default=get_last_semester, verbose_name=_("Semester"))
school_mode = models.IntegerField(db_index=True, choices=SCHOOL_MODE, verbose_name=_("School Type"))
year = models.IntegerField(db_index=True, choices=CLASS_YEARS, verbose_name=_("Year"))
brunch = models.CharField(max_length=2, verbose_name=_("Class Brunch"))
subject = models.CharField(max_length=15, choices=CLASS_SUBJECTS, verbose_name=_("Subject"))
teacher = models.ManyToManyField(Staff, blank=True, verbose_name=_("Class Teachers"))
class Meta:
unique_together = ('semester', 'year', 'brunch')
ordering = ['semester', 'year', 'brunch', 'subject']
def __unicode__(self):
return "%d %s %s %s / %s" % (self.semester, self.year, self.brunch, self.subject)
class Staff(BaseModel):
photo = models.ImageField(upload_to="Staff/", null=True, blank=True, verbose_name=_("Photo"))
user = models.OneToOneField(User, on_delete=models.PROTECT, db_index=True, verbose_name=_("User"))
name = models.CharField(max_length=30, db_index=True, verbose_name=_("Name"))
surname = models.CharField(max_length=30, db_index=True, verbose_name=_("Surname"))
id_no = models.CharField(max_length=15, unique=True,verbose_name=_("ID Card Number"))
birthdate = models.DateField(verbose_name=_("Birthdate"))
birthplace = models.CharField(max_length=30, verbose_name=_("Birthplace"))
gender = models.IntegerField(choices=GENDERS, default=None, verbose_name=_("Gender"))
nationality = models.CharField(choices=NATIONALITIES, max_length=20, verbose_name=_("Nationality"))
blood_type = models.CharField(choices=BLOOD_TYPES, null=True, blank=True, max_length=10, verbose_name=_("Blood Type"))
phone_home = models.CharField(max_length=15, null=True, blank=True, verbose_name=_("Phone Home"))
phone_mobile = models.CharField(max_length=15, null=True, blank=True, verbose_name=_("Phone Mobile"))
email = models.EmailField(default=None, null=True, blank=True, verbose_name=_("Email Address"))
address = models.TextField(verbose_name=_("Address"))
brunch = models.ForeignKey(TeacherBrunch, on_delete=models.PROTECT, verbose_name=_("Brunch"))
staff_type = models.ManyToManyField(StaffType, verbose_name=_("Staff Type"))
staff_status = models.IntegerField(choices=STAFF_STATUS, default=1, verbose_name=_("Staff Status"))
additional_information = models.CharField(max_length=100, null=True, blank=True, verbose_name=_("Additional Information"))
class Meta:
ordering = ['name', 'surname']
def __unicode__(self):
return "%s %s" % (self.name, self.surname)
def save(self, *args, **kwargs):
self.name = self.name.title()
self.surname = self.surname.upper()
self.user.save()
super(Staff, self).save(*args, **kwargs)

How to calculate the total price of products just by increasing quantity?

I have custorder models in which im taking product and price as foreign key from other models Product and price . I want to calculate the total price of product just by increasing quantity. Im just building a rest api for order creation . Please help me how to do it.
Models.py
class Product(models.Model):
product_id = models.AutoField(primary_key=True)
product = ArrayField(models.CharField(max_length=200, blank=True))
def __str__(self):
return str(self.product)
class Price(models.Model):
product = models.ForeignKey('Product',on_delete=models.CASCADE)
price_id = models.AutoField(primary_key=True)
price = models.DecimalField(max_digits=50, decimal_places = 5, default=0)
def __str__(self):
return "%s" % self.price
class CustOrder(models.Model):
Customer_id = models.AutoField(primary_key=True)
CustomerName = models.CharField(max_length=200)
email = models.EmailField(max_length=70,blank=True, null= True, unique= True)
gender = models.CharField(max_length=6, choices=GENDER_CHOICES)
phone = PhoneField(null=False, blank=True, unique=True)
landmark = models.PointField()
#landmark = models.TextField(max_length=400, help_text="Enter the landmark", default='Enter landmark')
houseno = models.IntegerField(default=0)
#product_name = models.CharField(max_length=200, choices=PRODUCT_CHOICES,default='Boneless chicken')
# product_id = models.ForeignKey(Product, on_delete=models.CASCADE,related_name='custorder_productid')
product = models.ManyToManyField(Product, blank=True,related_name='pricetag')
quantity = models.IntegerField(default=0)
# price_id = models.ForeignKey(Price)
price = models.ForeignKey(Price, on_delete=models.SET_NULL, null=True,related_name='pricetag')
#price = models.DecimalField(max_digits=50, decimal_places=5, default=48.9)
pay_method = models.CharField(max_length=200,choices=PAYMENT_CHOICES, default='RAZOR PAY')
city = models.ForeignKey(City, on_delete=models.SET_NULL, null=True)
area = models.ForeignKey(Area, on_delete=models.SET_NULL, null=True)
def __str__(self):
return self.CustomerName

How can I allow a user to filter models dynamically and export only certain fields?

I've been asked to design a way for people to search through multiple models on criteria they enter and allow them to export any number of fields they select.
Example:
User enters "Teacher" as a term for Job Title and "Google" for a Work Site Location but want to export "Employee ID", "First Name", "Last Name", "Date of Birth"
I'm sure this is possible, but I'm at a complete loss for where to start.
My models (for reference) are here:
import datetime
from django.conf import settings
from django.db import models
from django.db.models import Q
from django.utils import timezone
class Classification(models.Model):
name = models.CharField(max_length=255, blank=False, null=False, verbose_name='Classification Name')
def __str__(self):
return '{}'.format(self.name)
class Meta:
db_table = 'Classification'
verbose_name = 'Classification'
verbose_name_plural = 'Classifications'
class Location(models.Model):
name = models.CharField(max_length=255, blank=False, null=False, verbose_name='Name')
aeries_id = models.CharField(max_length=25, blank=True, null=True, verbose_name='Aeries ID')
county_id = models.CharField(max_length=25, blank=True, null=True, verbose_name='County ID')
def __str__(self):
return '{}'.format(self.name)
class Meta:
db_table = 'Location'
verbose_name = 'Location'
verbose_name_plural = 'Locations'
ordering = ['name']
class Person(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET_NULL, blank=True, null=True)
current_identity = models.ForeignKey('PersonIdentity', blank=True, null=True, on_delete=models.SET_NULL, verbose_name='Current Identity', related_name='current_identity')
employee_id = models.CharField(max_length=255, null=False, blank=False, verbose_name='Employee ID')
birthdate = models.DateField(blank=True, null=True, verbose_name='Birthdate')
original_hire_date = models.DateField(blank=True, null=True, verbose_name='Original Hire Date')
def __str__(self):
if self.current_identity is not None:
return '{}'.format(str(self.current_identity))
else:
return "{}".format(self.employee_id)
#property
def current_age(self):
from dateutil.relativedelta import relativedelta
difference_in_years = relativedelta(timezone.now().date(), self.birthdate).years
return difference_in_years
def primary_assignment(self):
return self.jobassignment_set.filter(Q(end_date__gte=timezone.now()) | Q(end_date=None)).order_by('priority')[0]
#property
def display_name(self):
if self.current_identity:
return '{0.first_name} {0.last_name} ({1.employee_id})'.format(self.current_identity, self)
else:
return 'Employee ID {0.employee_id}'.format(self)
#property
def is_certificated(self):
assignments = JobAssignment.objects.filter(Q(end_date__gte=timezone.now()) | Q(end_date=None)).filter(
person=self,
classification__name__icontains="Certificated"
)
return assignments.count() >= 1
class Meta:
db_table = 'Person'
verbose_name = 'Person'
verbose_name_plural = 'People'
class PersonIdentity(models.Model):
person = models.ForeignKey(Person, verbose_name='Person', on_delete=models.CASCADE)
first_name = models.CharField(max_length=50, blank=True, null=True, verbose_name='First Name')
middle_name = models.CharField(max_length=50, blank=True, null=True, verbose_name='Middle Name')
last_name = models.CharField(max_length=50, blank=True, null=True, verbose_name='Last Name')
start_date = models.DateField(blank=False, null=False, default=datetime.date.today, verbose_name='Start Date')
end_date = models.DateField(blank=True, null=True, verbose_name='End Date')
def __str__(self):
first_name = '' if self.first_name is None else self.first_name
last_name = '' if self.last_name is None else self.last_name
if self.middle_name is not None and self.middle_name != '':
return "{} {}. {} ({})".format(first_name, self.middle_name[0], last_name, self.person.employee_id)
else:
return "{} {} ({})".format(first_name, last_name, self.person.employee_id)
def save(self, *args, **kwargs):
change_identity = False
if not self.id:
change_identity = True
super().save(*args, **kwargs)
if change_identity:
self.person.current_identity = self
self.person.save()
class Meta:
db_table = 'PersonIdentity'
verbose_name = 'Person Identity'
verbose_name_plural = 'Person Identities'
ordering = ['end_date', 'last_name', 'first_name']
class Contact(models.Model):
person = models.OneToOneField(Person, on_delete=models.CASCADE, verbose_name='Person')
email_address = models.EmailField(blank=True, null=True, verbose_name='Primary Email')
phone_number = models.CharField(max_length=15, blank=True, null=True, verbose_name='Phone Number')
phone_extension = models.CharField(max_length=255, blank=True, null=True, verbose_name='Phone Extension')
address1 = models.CharField(max_length=255, blank=True, null=True, verbose_name='Address 1')
address2 = models.CharField(max_length=255, blank=True, null=True, verbose_name='Address 2')
city = models.CharField(max_length=255, blank=True, null=True, verbose_name='City')
state = models.CharField(max_length=2, default='CA', blank=True, null=True, verbose_name='State')
postal = models.CharField(max_length=5, blank=True, null=True, verbose_name='Postal Code')
def __str__(self):
return '{}'.format(self.person.current_identity)
class Meta:
db_table = 'Contact'
verbose_name = 'Contact'
verbose_name_plural = 'Contacts'
class Department(models.Model):
department_id = models.CharField(max_length=5, blank=False, null=False, verbose_name='Department ID')
description = models.CharField(max_length=255, blank=False, null=False, verbose_name='Department Description')
def __str__(self):
return '{}'.format(self.description)
class Meta:
db_table = 'Department'
verbose_name = 'Department'
verbose_name_plural = 'Departments'
class Job(models.Model):
name = models.CharField(max_length=255, blank=False, null=False, verbose_name='Name')
code = models.CharField(max_length=255, blank=False, null=False, verbose_name='Code')
def __str__(self):
return '{}'.format(self.name)
class Meta:
db_table = 'Job'
verbose_name = 'Job'
verbose_name_plural = 'Jobs'
class JobPosition(models.Model):
job = models.ForeignKey(Job, blank=True, null=True, verbose_name='Job')
reports_to = models.ForeignKey('JobPosition', blank=True, null=True, verbose_name='Reports To')
name = models.CharField(max_length=255, blank=True, null=True, verbose_name='Name')
number = models.CharField(max_length=255, blank=False, null=False, verbose_name='Number')
def __str__(self):
return '{}'.format(self.name)
class Meta:
db_table = 'JobPosition'
verbose_name = 'Job Position'
verbose_name_plural = 'Job Positions'
class JobAssignment(models.Model):
person = models.ForeignKey(Person, blank=False, null=False, verbose_name='Person')
position = models.ForeignKey(JobPosition, blank=False, null=False, verbose_name='Position')
location = models.ForeignKey(Location, blank=True, null=True, verbose_name='School')
classification = models.ForeignKey(Classification, blank=True, null=True, verbose_name='Classification')
start_date = models.DateField(blank=True, null=True, verbose_name='Start Date')
end_date = models.DateField(blank=True, null=True, verbose_name='End Date')
effective_date = models.DateField(blank=True, null=True, verbose_name='Effective Date')
fte = models.CharField(max_length=10, blank=True, null=True, verbose_name='FTE')
seniority_date = models.DateField(blank=True, null=True, verbose_name='Seniority Date')
last_start_date = models.DateField(blank=True, null=True, verbose_name='Last Start Date')
last_pay_date = models.DateField(blank=True, null=True, verbose_name='Last Pay Date')
entry_date = models.DateField(blank=True, null=True, verbose_name='Position Entry Date')
record_number = models.IntegerField(default=0, verbose_name='Position Record Number')
pay_group = models.CharField(max_length=3, blank=True, null=True, verbose_name='Pay Group')
indicator = models.CharField(max_length=1, blank=True, null=True, verbose_name='Indicator')
full_or_part_time = models.CharField(max_length=1, blank=True, null=True, verbose_name='Full/Part')
standard_hours_per_week = models.DecimalField(max_digits=5, decimal_places=2, blank=True, null=True, verbose_name='Standard Hours per Week')
pay_status = models.CharField(max_length=1, blank=True, null=True, verbose_name='Pay Status')
comp_rate = models.DecimalField(max_digits=15, decimal_places=6, blank=True, null=True, verbose_name='Comp Rate')
comp_frequency = models.CharField(max_length=10, blank=True, null=True, verbose_name='Comp Freq')
hourly_rate = models.DecimalField(max_digits=10, decimal_places=6, blank=True, null=True, verbose_name='Hrly Rate')
daily_rate = models.DecimalField(max_digits=10, decimal_places=6, blank=True, null=True, verbose_name='Daily Rt')
rate_code = models.CharField(max_length=10, blank=True, null=True, verbose_name='Rate Code')
compensation_rate = models.DecimalField(max_digits=15, decimal_places=6, blank=True, null=True, verbose_name='Compensation Rate')
total_cdays = models.DecimalField(max_digits=5, decimal_places=2, blank=True, null=True, verbose_name='TOTAL_CDAYS')
teacher_hours = models.DecimalField(max_digits=4, decimal_places=2, blank=True, null=True, verbose_name='Teacher Hours')
def __str__(self):
return '{} - {}'.format(self.position.name, self.position.number)
#classmethod
def current_assignments(cls):
return cls.objects.filter(Q(end_date__gte=timezone.now()) | Q(end_date=None)).exclude(person__ssn__isnull=True).exclude(person__current_identity__isnull=True).exclude(person__contact__isnull=True)
class Meta:
db_table = 'JobAssignment'
verbose_name = 'Job Assignment'
verbose_name_plural = 'Job Assignments'
ordering = ['location__name', 'person__current_identity__last_name', 'person__current_identity__first_name', 'position__name']