Migrating back-end from flask to django

13 views
Skip to first unread message

oganga chantal

unread,
Nov 3, 2018, 12:39:40 PM11/3/18
to Django users
need help with creating models for my django app,

Igor Nascimento

unread,
Nov 3, 2018, 1:02:29 PM11/3/18
to django...@googlegroups.com
Hi,

I'm migrating my Flask app to a Django app. In cases of the models, it's a little different between both. In Flask, you have to put id and in Django it's not necessary. I'm showing you the difference between Flask and Django while creating models. It's important to say that I was using Flask_SQLAlchemy to make my models. Django has a pattern library that comes along the framework.

Flask:
from flask_sqlalchemy import SQLAlchemy

class Friend(db.Model):
    __tablename__ = "friends"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String, nullable=False)
    address = db.Column(db.String, nullable=True)


Django:
from django.db import models

class Friend(models.Model):
    name = models.CharField(max_length=100)
    address = models.CharField(max_length=64, default=None)

As you can see, in Django is a little simpler to make models. You only have to put the max_length. The NULL statement is equal to say default=None in Django models.

Anytime,
Igor


Em sáb, 3 de nov de 2018 às 09:39, oganga chantal <oganga...@gmail.com> escreveu:
need help with creating models for my django app,

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/fde1cd1f-7d1e-4ac0-94d0-a41b06e9516f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages