Coder Social home page Coder Social logo

django-validations's Introduction

Validations

More than just preventing "bad" or "incomplete" data, an application's models can enforce domain rules & requirements. Most applications take a layered approach to data integrity.

Database Model Interface
Core Middle Layer Outer Layer

Interface

At the outermost layer, you have the program's interface, e.g. an HTML form that only allows a user to enter an email address that contains @.

Model

The next level of validation is often performed by the application's models. One approach might be to overwrite the .save method like so:

def save(self, *args, **kwargs):
    if len(self.first_name) < 1
        raise ValidationError(_('Name must be longer than one letter'), code='invalid')

    super(SwimRecord, self).save(*args, **kwargs)
   

While this works, it isn't very scalable. Django takes a different approach.

Database

The final level of validation is usually performed by the database. Often with NOT NULL constraints or particular column types (integer vs varchar(255) or char(14)).


Challenge

This challenge will have you exploring the Django docs (and any other resources you find online) to resolve some errors and ultimately make the tests pass. We are working with one model. The attributes are written for you and commented out - they are also incomplete. You'll have to add some settings to what is there to get the first few tests to pass.

The last batch of tests will require you to write your own validations.

Release 0: Setup

Create a virtual env. Start it up. Then tell pip to read the requirements.txt file and install all the requirements.

python -m venv venv 

source venv/bin/activate

pip install -r requirements.txt

Release 1

Run the test with the following command.

python manage.py test

The first four tests will pass because of the nature of full_clean(). We've commented out the attributes in the model. Your job is to figure out what code needs to be added to each attribute to truly pass each test.

If you get an error saying the test db already exists you should be able to type yes to destroy it and create a new one.

Using the skeleton found in models.py, your job is to uncomment out each column one by one and make the tests pass.

Release 2

This challenge includes one model SwimRecord. Follow the tests in swimrecords/tests.py, adding any missing validations using those provided by Django

Some validations can be implemented by using functions provided by Django, but for some tests, you'll need to create your own validation methods.

django-validations's People

Contributors

chad-mowbray avatar crhowell avatar jalletto avatar jyoung217 avatar karinmatsuyama avatar mic-j-lee avatar tomprete avatar wynspeare avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.