Cleaning service API using Django REST framework












0














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')









share|improve this question
















bumped to the homepage by Community yesterday


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.




















    0














    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')









    share|improve this question
















    bumped to the homepage by Community yesterday


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.


















      0












      0








      0







      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')









      share|improve this question















      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')






      python django






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Sep 23 '17 at 17:26









      Jamal

      30.3k11116226




      30.3k11116226










      asked Sep 23 '17 at 8:29









      user149459

      72




      72





      bumped to the homepage by Community yesterday


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community yesterday


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Are the cleaners and clients supposed to be authenticated, maybe they should inherit from AUTH_USER_MODE or a base user? When using the ORM you want the object to have the name to the models on the foreign Key i.e client = models.ForeignKey(Client). By default, all these models have indexes for the pk, are your querying every object using the pk (i.e the id)?






          share|improve this answer























            Your Answer





            StackExchange.ifUsing("editor", function () {
            return StackExchange.using("mathjaxEditing", function () {
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
            });
            });
            }, "mathjax-editing");

            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "196"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f176365%2fcleaning-service-api-using-django-rest-framework%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Are the cleaners and clients supposed to be authenticated, maybe they should inherit from AUTH_USER_MODE or a base user? When using the ORM you want the object to have the name to the models on the foreign Key i.e client = models.ForeignKey(Client). By default, all these models have indexes for the pk, are your querying every object using the pk (i.e the id)?






            share|improve this answer




























              0














              Are the cleaners and clients supposed to be authenticated, maybe they should inherit from AUTH_USER_MODE or a base user? When using the ORM you want the object to have the name to the models on the foreign Key i.e client = models.ForeignKey(Client). By default, all these models have indexes for the pk, are your querying every object using the pk (i.e the id)?






              share|improve this answer


























                0












                0








                0






                Are the cleaners and clients supposed to be authenticated, maybe they should inherit from AUTH_USER_MODE or a base user? When using the ORM you want the object to have the name to the models on the foreign Key i.e client = models.ForeignKey(Client). By default, all these models have indexes for the pk, are your querying every object using the pk (i.e the id)?






                share|improve this answer














                Are the cleaners and clients supposed to be authenticated, maybe they should inherit from AUTH_USER_MODE or a base user? When using the ORM you want the object to have the name to the models on the foreign Key i.e client = models.ForeignKey(Client). By default, all these models have indexes for the pk, are your querying every object using the pk (i.e the id)?







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Oct 6 '18 at 14:56









                Stephen Rauch

                3,76061630




                3,76061630










                answered Oct 6 '18 at 9:14









                Harrison

                11




                11






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Code Review Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    Use MathJax to format equations. MathJax reference.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f176365%2fcleaning-service-api-using-django-rest-framework%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    How to reconfigure Docker Trusted Registry 2.x.x to use CEPH FS mount instead of NFS and other traditional...

                    is 'sed' thread safe

                    How to make a Squid Proxy server?