Code Monkey home page Code Monkey logo

staruml-django's Introduction

Spanish Translation

StartUML extension to auto generate Django Models

Features

  • Auto-generate Django Model Class.
  • Auto-generate attributes with the suitable type, using standard Djando Model Field, provided by Django ORM.
  • Generate inheritance, (if not exist by default models.Model).
  • Generate relationship, using cardinality, create suitable fields, OneToOne, ForeingKey and ManyToMany.
  • Auto add attributes in Meta models, using tags.
  • Auto add aditional params to model attributes and model relationships fields using defined tags.

Requirements

To run auto-generate field with suitable Django Mode Field, is necesary to have a diagram with a class for each basic type loaded.

You could download this scheme with basic class types

Basic Types

  • string: models.CharField
  • text: models.TextField
  • integer: models.IntegerField
  • decimal: models.DecimalField
  • boolean: models.BooleanField
  • date: models.DateField
  • datetime: models.DateTimeField
  • email: models.EmailField
  • file: models.FileField

Installation

1- Install StarUML, download page.

2- Download or clone this repo.

3- Copy repo files to StarUML extension user folder.

  • MacOS: ~/Library/Application Support/StarUML/extensions/user/staruml-django

  • Windows: C:\Users\<user>\AppData\Roaming\StarUML\extensions\user\staruml-django

  • Linux: ~/.config/StarUML/extensions/user/staruml-django

Usage

  1. Click the menu (Tools > Django Models > Generate Code...)
  2. Select a base model (or package) that will be generated to Django Models.
  3. Select a folder where generated Python source files (.py) will be placed.

Sample

AbstactStudent Model

#-*- coding: utf-8 -*-

from django.db import models

class AbstractStudent(models.Model):
    class Meta:
        verbose_name='foo'

    type = models.CharField()

Student Model

#-*- coding: utf-8 -*-

from django.db import models
from AbstractStudent import AbstractStudent

class Student(AbstractStudent):
    class Meta:
        verbose_name='student'

    name = models.CharField(max_length=1024, verbose_name='name', null=True)
    surname = models.CharField()
    birthdate = models.DateField()

    school = models.ForeingKey('School', on_delete=models.PROTECT)
    teachers = models.ManyToMany('Teacher')
    expedient = models.OneToOne('Expedient')

    @property
    def age(self, ):
        pass

Teacher Model

#-*- coding: utf-8 -*-

from django.db import models

class Teacher(models.Model):
    class Meta:
        pass

    name = models.CharField()
    speciality = models.CharField()

    school = models.ForeingKey('School', related_name='teachers', on_delete=models.PROTECT)

School Model

#-*- coding: utf-8 -*-

from django.db import models

class School(models.Model):
    class Meta:
        pass

    name = models.CharField()
    address = models.CharField()

Expedient Model

#-*- coding: utf-8 -*-
from django.db import models

class Expedient(models.Model):
    class Meta:
        pass

    qualification = None

Disclainer

This project is now in beta, not ready for production or profesional use. Use and modify by your own responsability.

Contributors

staruml-django's People

Contributors

josemlp91 avatar lecbg avatar mercedesromo avatar quantumcharleshill avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

staruml-django's Issues

I am unable to get the conversion to django model to work

hello @josemlp91 , I downloaded the basic type installed the extension, but i am unable to get the conversion to correct django model type to work .

this an example of model class that i get:

from django.db import models

class Purchase_Order(models.Model):
    class Meta:
        pass

    ID String = None
    Supplier String = None
    Date_Issued Date = None
    Attribute1 = None

AttributeError on ManyToMany and OneToOne

Django throws the following errors in code generated with the plugin:

  • AttributeError: module 'django.db.models' has no attribute 'OneToOne'
  • AttributeError: module 'django.db.models' has no attribute 'ManyToMany'

Following Django's docs, models.OneToOne and models.ManyToMany in the lines below should be substituted with models.OneToOneField and models.ManyToManyField in order to fix the error.

codeWriter.writeLine(var_name + " = models.OneToOne('" + refObjName + "'"+ tags_str +")");

codeWriter.writeLine(var_name + " = models.ManyToMany('" + asso.end2.reference.name + "'"+ tags_str +")");

Error on boolean attributes when checked

code-generator.js line 135 throws an error when you have a boolean and it is checked. This causes the rest of the models not to build. No fun :'(

Simply change e.name to tag.name and everything works. I verified this by modifying my local install.

      else if (tag.kind == 'boolean') {
        if (tag.checked) {
-          codeWriter.writeLine(e.name + '=True');
+          codeWriter.writeLine(tag.name + '=True');
        }
        else {
          codeWriter.writeLine(tag.name + '=False');
        }
      }

Is this still supported?

Hi there,

I'm planning on using this in an upcoming project. I'm wondering if it's still supported, as I'm not seeing many recent commits. Any info would be greatly appreciated.

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.