Related
I want to make pay form, but I cannot show produk in orederitem, please helping me to show orderitem :v. I am really newbie in here .
models.py
class Order(models.Model):
name = models.ForeignKey(Profile, on_delete=models.SET_NULL, blank=True, null=True)
order_data = models.DateTimeField(auto_now_add=True)
selesai = models.BooleanField(default=False, blank=True, null=True)
status = models.BooleanField(default=False, blank=True, null=True)
id_transaksi = models.CharField(max_length=200, null=True)
bukti = models.ImageField(null=True, blank=True)
ongkir = models.CharField(max_length=200, null=True)
total = models.CharField(max_length=200, null=True)
total_harga = models.CharField(max_length=200, null=True)
pembayaran = models.CharField(max_length=200, null=True)
class OrderItem(models.Model):
product = models.ForeignKey(Product, on_delete=models.SET_NULL, blank=True, null=True)
order = models.ForeignKey(Order, on_delete=models.SET_NULL, blank=True, null=True)
quantity = models.IntegerField(default=0)
date_added = models.DateTimeField(auto_now_add=True)
views.py
def pembayaran(request):
customer = request.user.profile
ido = Order.objects.filter(id)
orders = Order.objects.filter(name=customer, selesai=True)
pengiriman = Pengiriman.objects.filter(name=customer)
OrderItems = OrderItem.objects.filter(order=ido)
print(OrderItems)
context = {'orders': orders,'pengiriman' :pengiriman , 'OrderItems': OrderItems }
return render(request, 'store/pembayaran.html', context)
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)
I am facing problem.
code in template alumni_cv.html:
<a href="{% url 'alumni_cv' user.alumniprofile.id %}"
class="btn
btn-primary btn-block"><b>CV</b></a>
When I click this button, the following error appears:
NoReverseMatch at /alumni/2/alumni_cv/
Reverse for 'alumni_profile' with arguments '('',)' not found. 1 pattern(s)
tried: ['alumni/alumni_profile/(?P<pk>[^/]+)/$']
models.py code:
class AlumniProfile(models.Model):
user = models.OneToOneField(User, null=True, on_delete=models.CASCADE)
phone = models.CharField(max_length=50)
occupation = models.CharField(max_length=50)
image = models.ImageField(
upload_to='alumni/', null=True, blank=True, default="default_user_avatar.jpg")
bio = models.TextField()
date_of_birth = models.DateField(null=True, blank=True)
district_of_birth = models.ForeignKey(
TownCityDistrict, on_delete=models.CASCADE, null=True, blank=True)
gender = models.CharField(max_length=20, choices=genders)
present_address = models.CharField(max_length=254)
permanent_address = models.CharField(max_length=254)
blood_group = models.CharField(max_length=10, choices=blood_groups)
university_bachelor_session = models.CharField(max_length=50)
university_masters_session = models.CharField(max_length=50)
university_hall = models.CharField(max_length=100)
university_batch = models.CharField(max_length=20)
slug = models.SlugField()
facebook_url = models.URLField(blank=True, null=True)
linkedin_url = models.URLField(blank=True, null=True)
instagram_url = models.URLField(blank=True, null=True)
twitter_url = models.URLField(blank=True, null=True)
skype_id = models.CharField(max_length=100, blank=True, null=True)
zoom_id = models.CharField(max_length=100, blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
visible_to_public = models.BooleanField(default=True)
def __str__(self):
return str(self.phone)
class Meta:
verbose_name_plural = 'Alumni'
class AlumniEducation(models.Model):
user = models.ForeignKey(AlumniProfile, null=True,
on_delete=models.CASCADE)
exam = models.CharField(
max_length=50, verbose_name='Examination/Degree', blank=True, null=True)
exam_year = models.DateField(
verbose_name='Examination Year', blank=True, null=True)
institute = models.CharField(
max_length=100, verbose_name='Institute Name', blank=True, null=True)
board_university = models.CharField(
max_length=50, verbose_name='Board/University', blank=True, null=True)
result = models.CharField(
verbose_name='Result/Grade', max_length=20, blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
visible_to_public = models.BooleanField(default=True)
def __str__(self):
return self.exam
class Meta:
verbose_name_plural = 'Education Profile'
class AlumniJobExperience(models.Model):
user = models.ForeignKey(AlumniProfile, null=True, blank=True,
on_delete=models.CASCADE)
company = models.CharField(max_length=50, blank=True, null=True)
job_location = models.CharField(max_length=50, blank=True, null=True)
designation = models.CharField(max_length=50, blank=True, null=True)
date_of_join = models.DateField(blank=True, null=True)
now_on_job = models.BooleanField(blank=True, null=True)
date_of_resignation = models.DateField(blank=True, null=True)
responsibilities = models.TextField(blank=True, null=True)
achievements = models.TextField(blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
visible_to_public = models.BooleanField(default=True)
def __str__(self):
return self.company
class Meta:
verbose_name_plural = 'Job Experience'
class AlumniProfessionalSkill(models.Model):
professional_skill = models.CharField(max_length=30, blank=True, null=True)
professional_skill_rating = models.IntegerField(
validators=[MinValueValidator(0), MaxValueValidator(100)], blank=True, null=True)
user = models.ForeignKey(
AlumniProfile, null=True, on_delete=models.CASCADE)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
visible_to_public = models.BooleanField(default=True)
def __str__(self):
return str(self.professional_skill)
class Meta:
verbose_name_plural = 'Professional Skills'
class AlumniLanguageSkill(models.Model):
language_skill = models.CharField(max_length=40)
language_skill_rating = models.IntegerField(null=True,
validators=[MinValueValidator(1), MaxValueValidator(5)])
user = models.ForeignKey(
AlumniProfile, null=True, on_delete=models.CASCADE)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
visible_to_public = models.BooleanField(default=True)
def __str__(self):
return str(self.language_skill)
class Meta:
verbose_name_plural = 'Language Skills'
class AlumniComputerSkill(models.Model):
computer_skill = models.CharField(max_length=40)
computer_skill_rating = models.IntegerField(null=True,
validators=[MinValueValidator(1), MaxValueValidator(5)])
user = models.ForeignKey(
AlumniProfile, null=True, on_delete=models.CASCADE)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
visible_to_public = models.BooleanField(default=True)
def __str__(self):
return str(self.computer_skill)
class Meta:
verbose_name_plural = 'Computer Skills'
constraints = [
models.UniqueConstraint(
fields=['user', 'computer_skill'], name='unique_user_computer_skill'),
]
class AlumniTraining(models.Model):
user = models.ForeignKey(AlumniProfile, null=True,
on_delete=models.CASCADE)
training_title = models.CharField(max_length=254, blank=True, null=True)
training_date = models.DateField(blank=True, null=True)
trainer = models.CharField(max_length=100, blank=True, null=True)
training_location = models.CharField(max_length=70, blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
visible_to_public = models.BooleanField(default=True)
def __str__(self):
return str(self.training_title)
class Meta:
verbose_name_plural = 'Trainings'
class AlumniProfessionalCertification(models.Model):
user = models.ForeignKey(AlumniProfile, null=True,
on_delete=models.CASCADE)
professional_certificate_title = models.CharField(
max_length=254, blank=True, null=True)
certification_date = models.DateField(blank=True, null=True)
organization_name = models.CharField(max_length=100, blank=True, null=True)
organization_location = models.CharField(
max_length=70, blank=True, null=True)
certificate_attachment = models.FileField(
upload_to='certificates/', null=True, blank=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
visible_to_public = models.BooleanField(default=True)
def __str__(self):
return self.professional_certificate_title
class Meta:
verbose_name_plural = 'Certifications'
class OthersActivities(models.Model):
user = models.ForeignKey(AlumniProfile, null=True,
on_delete=models.CASCADE)
activities_hobbies = models.CharField(
max_length=100, blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
visible_to_public = models.BooleanField(default=True)
def __str__(self):
return self.activities_hobbies
class Meta:
verbose_name_plural = 'Activities/Hobbies'
class AlumniPublication(models.Model):
pubication_title = models.CharField(max_length=254, blank=True, null=True)
pubication_journal = models.CharField(
max_length=254, blank=True, null=True)
published_on = models.DateField(blank=True, null=True)
publication_link = models.URLField(blank=True, null=True)
user = models.ForeignKey(AlumniProfile, null=True,
on_delete=models.CASCADE)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
visible_to_public = models.BooleanField(default=True)
def __str__(self):
return self.pubication_title
class Meta:
verbose_name_plural = 'Publications'
class AlumniTestimonial(models.Model):
user = models.ForeignKey(AlumniProfile, null=True,
on_delete=models.CASCADE)
commented_by = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
comment = models.TextField(null=True, blank=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
visible_to_public = models.BooleanField(default=True)
def __str__(self):
return self.comment
class Meta:
verbose_name_plural = 'Testimonials'
class ServicesProvidedByAlumni(models.Model):
user = models.ForeignKey(AlumniProfile, null=True,
on_delete=models.CASCADE)
service = models.CharField(max_length=50, null=True, blank=True)
image = models.ImageField(upload_to='services/', blank=True, null=True)
service_short_description = models.CharField(
max_length=254, null=True, blank=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
visible_to_public = models.BooleanField(default=True)
def __str__(self):
return str(self.service)
class Meta:
verbose_name_plural = 'Services Provided by Alumni'
class AlumniProfileSettings(models.Model):
user = models.ForeignKey(AlumniProfile, null=True,
on_delete=models.CASCADE)
date_of_birth_visible_to_public = models.BooleanField(default=True)
place_of_birth_visible_to_public = models.BooleanField(default=True)
phone_visible_to_public = models.BooleanField(default=True)
email_visible_to_public = models.BooleanField(default=True)
facebook_url_visible_to_public = models.BooleanField(default=True)
linkedin_url_visible_to_public = models.BooleanField(default=True)
instagram_url_visible_to_public = models.BooleanField(default=True)
twitter_url_visible_to_public = models.BooleanField(default=True)
skype_id_visible_to_public = models.BooleanField(default=True)
zoom_id_visible_to_public = models.BooleanField(default=True)
social_media_url_visible_to_public = models.BooleanField(default=True)
profile_pic_of_birth_visible_to_public = models.BooleanField(default=True)
present_address_visible_to_public = models.BooleanField(default=True)
permanent_address_visible_to_public = models.BooleanField(default=True)
website_visible_to_public = models.BooleanField(default=True)
work_experience_visible_to_public = models.BooleanField(default=True)
professional_skill_visible_to_public = models.BooleanField(default=True)
language_skill_visible_to_public = models.BooleanField(default=True)
computer_skill_visible_to_public = models.BooleanField(default=True)
testimonials_visible_to_public = models.BooleanField(default=True)
achievements_visible_to_public = models.BooleanField(default=True)
trainings_visible_to_public = models.BooleanField(default=True)
certifications_visible_to_public = models.BooleanField(default=True)
services_visible_to_public = models.BooleanField(default=True)
personal_album_visible_to_public = models.BooleanField(default=True)
publications_visible_to_public = models.BooleanField(default=True)
cv_visible_to_public = models.BooleanField(default=True)
blood_group_visible_to_public = models.BooleanField(default=True)
profile_visible_to_public = models.BooleanField(default=True)
cv_downloadable_to_public = models.BooleanField(default=True)
cv_printable_to_public = models.BooleanField(default=True)
posts_visible_to_public = models.BooleanField(default=True)
comments_visible_to_public = models.BooleanField(default=True)
personal_info_visible_to_public = models.BooleanField(default=True)
contact_info_visible_to_public = models.BooleanField(default=True)
hobbies_other_activities_visible_to_public = models.BooleanField(
default=True)
def __str__(self):
return str(self.profile_visible_to_public)
Code for views.py:
#login_required(login_url='login')
def alumni_cv(request, pk):
alumniprofile = AlumniProfile.objects.filter(pk=pk)
education = AlumniEducation.objects.filter(user=pk).order_by('-exam_year')
jobexperience = AlumniJobExperience.objects.filter(
user=pk).order_by('-date_of_join')
alumniprofessionalskills = AlumniProfessionalSkill.objects.filter(user=pk)
alumnilanguageskills = AlumniLanguageSkill.objects.filter(user=pk)
alumnicomputerskills = AlumniComputerSkill.objects.filter(user=pk)
alumnitrainings = AlumniTraining.objects.filter(
user=pk).order_by('-training_date')
alumniprofessionalcertifications = AlumniProfessionalCertification.objects.filter(
user=pk)
alumniothersactivities = OthersActivities.objects.filter(user=pk)
alumnipublications = AlumniPublication.objects.filter(user=pk)
alumnitestimonials = AlumniTestimonial.objects.filter(user=pk)
alumniservices = ServicesProvidedByAlumni.objects.filter(user=pk)
alumniprofilesettings = AlumniProfileSettings.objects.filter(user=pk)
context = {'education': education, 'jobexperience': jobexperience, 'alumniprofile': alumniprofile,
'alumniprofessionalskills': alumniprofessionalskills, 'alumnilanguageskills': alumnilanguageskills,
'alumnicomputerskills': alumnicomputerskills, 'alumnitrainings': alumnitrainings,
'alumniprofessionalcertifications': alumniprofessionalcertifications,
'alumniothersactivities': alumniothersactivities, 'alumnipublications': alumnipublications,
'alumnitestimonials': alumnitestimonials, 'alumniservices': alumniservices,
'alumniprofilesettings': alumniprofilesettings}
return render(request, 'alumni_cv.html/', context)
urls.py code:
path('alumni_profile/<str:pk>/', alumni_profile, name='alumni_profile'),
url(r'^my_profile/(?P<pk>\d+)/$', my_profile, name='my_profile'),
url(r'^(?P<pk>\d+)/my_cv/$', my_cv, name='my_cv'),
# url(r'^(?P<pk>\d+)/alumni_cv/$', alumni_cv, name='alumni_cv'),
path('<str:pk>/alumni_cv/', alumni_cv, name='alumni_cv'),
Indenting is ok in my file.
Try {% url 'alumni_cv' alumniprofile.id %}
You can try path('<int:pk>/alumni_cv/', alumni_cv, name='alumni_cv'), (the type of pk is changed). If that didn't help please see django url dispatcher.
I´m trying to filter a queryset with a ForeignKey field but I get the following error:
Cannot resolve keyword 'workflowcontenidos' into field. Choices are:
categoria_producto, descripcion_brief, descripcion_long, estatus_contenido,
estatus_contenido_id, foto_1, foto_2, id, perfil_cliente, productosbase, usos,
video
My models are:
class WorkflowContenidos(models.Model):
estatus = models.CharField(max_length=200, help_text="Estatus de contenido", blank=False, null=True)
def __str__(self):
return str(self.estatus)
class Categorias_Producto(models.Model):
categoria_producto = models.CharField(max_length=50, help_text="Catergoría de producto", unique=True, blank=False, null=True)
descripcion_brief = models.TextField(max_length=200, help_text="Descripción resumida", blank=True, null=True)
descripcion_long = models.TextField(max_length=500, help_text="Descripción extendida", blank=True)
usos = models.CharField(max_length=200, help_text="Usos (separados por comas)", blank=True, null=True)
foto_2 = models.ImageField(upload_to='', default="", blank=False, null=False)
foto_1 = models.ImageField(upload_to='', default="", blank=False, null=False)
video = models.URLField("Link brand video", max_length=128, blank=True, null=True)
perfil_cliente = models.CharField(max_length=200, help_text="Perfil de cliente", blank=True, null=True)
estatus_contenido = models.ForeignKey("WorkflowContenidos", help_text="Estatus del contenido", blank=True, null=True, on_delete=models.CASCADE)
def __str__(self):
return str(self.categoria_producto)
The "estatus" values in the WorkflowContenidos model are:
Incompleto
Revisión
Aprobado
The view:
def WorkflowContenidosView(request):
lista_visualizacion = Categorias_Producto.objects.filter(workflowcontenidos__estatus='Incompleto')
return render(request, 'catalog/content-workflow.html', {
'lista_visualizacion': lista_visualizacion
})
lista_visualizacion = Categorias_Producto.objects.filter(estatus_contenido__estatus='Incompleto')
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']