Code Monkey home page Code Monkey logo

hello-django's Introduction

Demo Django Project

This is simple CRUD application that uses the Django framework. This project is based on the Django Workshop. To see full project that was the basis of the workshop, here is the link

Requirements

  • Django. Recommended version used is provided in requirements.txt in case problems occur
  • Virtualenv. It strongly recommended to always run in a sandboxed environment especially when working on mulitple projects. For more information please check out the official documentation.

How to run :

When the requirements have been installed first run the migration tool to initialize the database.

python manage.py migrate

This uses SQLite for portability.

Then :

python manage.py runserver

How it was done

currently work in progress

Create the Notes App

python manage.py startapp notes

This will create a note app.

Creating our model

we create our model

Under notes/models.py

class AuditModelMixin(models.Model):

    created_time = models.DateTimeField(auto_now_add=True)
    modified_time = models.DateTimeField(auto_now=True)

    class Meta:
        abstract = True


class Note(AuditModelMixin):
    title = models.CharField(max_length=129, blank=True)
    note = models.TextField(blank=True)

Here we create an abstract class AuditModelMixin, a class that we will inherit for reuse some fields such as created_time and modified_time

the Note class will be the model for the items we will be using

After creating our model, run

python manage.py makemigrations

This will generate sql migration scripts or files that will generate our tables. Then we will run

python manage.py migrate

To apply the changes in the database

Now that we have our tables, we can proceed in creating our views and template.

Preparing the Templates

The base Template

<!DOCTYPE html>
<html>
<head>
    <title>Notes App {{ page_title }}</title>
    <link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
<div class="container">
	<div class="row">
			<div class="col-md-12">		
				{% block content %}
				{% endblock %}
			</div>
	</div>
</div>
</body>
</html>

Save this file as base.html. This will serve as the page that we will extend for the other templates we will be using. We will then create those templates. Since the {% block content %} is where our content will go, just write the content you need on the template you will write.

TBA

hello-django's People

Contributors

jeremejazz avatar dependabot[bot] 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.