Django Data Entry

2019-07-21 11:44:49+00

With this story we want to enable data entry.

These are the tasks to be done:

  1. Generate a model in django based on an existing database table
  2. Create a view
  3. Create a controller

Generate a model based on an existing database table


python3.6 manage.py inspectdb entry
# This is an auto-generated Django model module.
# You'll have to do the following manually to clean this up:
#   * Rearrange models' order
#   * Make sure each model has one field with primary_key=True
#   * Make sure each ForeignKey has `on_delete` set to the desired behavior.
#   * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table
# Feel free to rename the models, but don't rename db_table values or field names.
from django.db import models

class Entry(models.Model):
    id = models.CharField(primary_key=True, max_length=36)
    user = models.ForeignKey('User', models.DO_NOTHING)
    created = models.DateTimeField(blank=True, null=True)
    modified = models.DateTimeField(blank=True, null=True)
    etyp = models.CharField(max_length=1)
    etitle = models.CharField(max_length=80)
    eurl = models.CharField(max_length=255, blank=True, null=True)
    etext = models.CharField(max_length=12000, blank=True, null=True)
    etagsingle = models.TextField(blank=True, null=True)  # This field type is a guess.

    class Meta:
        managed = False
        db_table = 'entry'

Tag: django22

Previous Chapter: Fast Application Development with Django 2.2