I've found there is a model framework for PostgreSQL:
from sqlalchemy import Column, Integer, String
from sqlalchemy.orm import column_property
from ..base import Base
class Staff(Base):
__tablename__ = 'account'
id = Column(Integer, primary_key=True)
name = column_property(Column(String(30), nullable=False))
surname = column_property(Column(String(30)))
otch = column_property(Column(String(30), nullable=False))
b_date = column_property(Column(String(30)))
pol = column_property(Column(String(3), nullable=False))
email = column_property(Column(String(100)))
gruppa = column_property(Column(String(30), nullable=False))
fak = column_property(Column(String(30)))
profile = column_property(Column(String(30), nullable=False))
There is a view that through a serializater must give details:
if request.method == 'GET':
session = request.sa_session
h = session.query(Staff).all()
for i in h:
print i.name
serializer = TaskSerializer(h, many=True)
return Response(serializer.data)
Description TaskSerializer:
from db.admin.db import Staff
from rest_framework import serializers
class TaskSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Staff
But when you run, there is an error:
type object 'Staff' has no attribute '_meta'
The joke is that if the model is built through Model.model:
from django.db import models
class Staff(models.Model):
name = models.CharField(max_length=30)
surname = models.CharField(max_length=30)
otch = models.CharField(max_length=30)
b_date = models.CharField(max_length=30)
pol = models.CharField(max_length=3)
email = models.CharField(max_length=100)
gruppa = models.CharField(max_length=30)
fak = models.CharField(max_length=30)
profile = models.CharField(max_length=30)
it all works.
Is it possible to use SQLAlchemy model or only Django's models.Model?