I am trying to write a cleaning service API using the Django REST framework, but I think how I defined this model is not robust enough for production and in turns will make any application using this API have a very slow response, example of what I'm saying is that the model has no indexes defined whatsoever.
Running around to see if am on the right track, I came across [this link][1] and I felt this model could be better refactored. Is there anything I can do to this to make this robust? I am as new as new in Python/Django.
models.py
from django.db import models class Cleaners(models.Model): created = models.DateTimeField(auto_now=True) firstName = models.CharField(max_length=50) lastName = models.CharField(max_length=50) location = models.CharField(max_length=50) address = models.CharField(max_length=100) bankName = models.CharField(max_length=100,default='zenith') bvn = models.IntegerField(null=True) verificationStatus = models.BooleanField(default=False) image = models.ImageField(upload_to='uploads/',height_field=50, width_field=50, max_length=100) phone = models.CharField(max_length=11,primary_key=True) class Meta: ordering = ('created',) class CleanersWork(models.Model): created = models.DateTimeField(auto_now_add=True) cleanerId = models.ForeignKey('Cleaners', on_delete=models.CASCADE) ratings = models.IntegerField() availability = models.BooleanField(default=True) jobHistory = models.IntegerField() currentEarning = models.DecimalField(max_digits=7,decimal_places=2) class Meta: ordering = ('created',) class Client(models.Model): created = models.DateTimeField(auto_now_add=True) firstName = models.CharField(max_length=50) lastName = models.CharField(max_length=50) address = models.CharField(max_length=100) verificationStatus = models.BooleanField(default=True) bvn = models.IntegerField(null=True) bankName = models.CharField(max_length=100,default='') image = models.ImageField(upload_to='uploads/',height_field=50,width_field=50,max_length=100) phone = models.CharField(max_length=11,primary_key=True) class Meta: ordering = ('created',) class Offering(models.Model): created = models.DateTimeField(auto_now_add=True) client_id = models.ForeignKey('Client',on_delete=models.CASCADE) totalJobPosted = models.IntegerField() ratings = models.IntegerField() availableFunds = models.DecimalField(max_digits=7,decimal_places=2) class Meta: ordering = ('created',) class Bookings(models.Model): client_id = models.ForeignKey('Client', null=False, blank=False, default='Client_Id') # Who is booking who ? I also don't want to CASCADE upon delete, we will need record of booking either is client deleted or not. cleaner_id = models.ForeignKey('Cleaners', null=False, blank=False, default='Cleaner_Id') # Who is being booked ? I also don't want to CASCADE upon delete, we will need record of booking either is cleaner deleted or not. startDate = models.DateField(auto_now=False) startTime = models.TimeField() extras = models.DecimalField(max_digits=7,decimal_places=2) price = models.DecimalField(max_digits=7,decimal_places=2) notes = models.TextField() created = models.DateTimeField(auto_now_add=True) class Meta: ordering = ('created',)
Here is my serializers.py in case you need a reference to it:
from rest_framework import serializers from laundry.models import Cleaners,CleanersWork,Client,Offering,Bookings class CleanerSerializer(serializers.ModelSerializer): class Meta: model = Cleaners fields = ('created','firstName','lastName','location','address','bankName','bvn','verificationStatus','phone') class CleanersWorkSerializer(serializers.ModelSerializer): class Meta: model = CleanersWork fields = ('created','cleanerId','ratings','availability','jobHistory','currentEarning') class ClientSerializer(serializers.ModelSerializer): class Meta: model = Client fields = ('created','firstName','lastName','address','verificationStatus','bvn','bankName','phone') class OfferingSerializer(serializers.ModelSerializer): class Meta: model = Offering fields = ('created','client_id','totalJobPosted','ratings','availableFunds') class BookingsSerializer(serializers.ModelSerializer): class Meta: model = Bookings fields = ('client_id', 'cleaner_id', 'startDate','startTime', 'extras', 'price', 'notes', 'created')