Git Product home page Git Product logo

Comments (1)

Thaza-Kun avatar Thaza-Kun commented on June 21, 2024

Punca

Sejak a893b6d, saya tambah model Keizinan yang mewarisi BaseStrictTable. BaseStrictTable memastikan senarai data dalam jadual itu tidak ditambah sesuka hati (sebab keizinan hanya ada beberapa jenis sahaja, berbeza dengan jumlah pengguna yang boleh bertambah sebanyak-banyaknya), tetapi saya lupa memasukkan kaedah mengisi keizinan jadi apa-apa data yang bergantung kepada Keizinan akan gagal sebab tiada data keizinan.

# samudra/models/base.py
class BaseStrictTable(BaseTable):
    @classmethod
    def get_or_create(cls, **kwargs):
       # Saya matikan kaedah `get_or_create` untuk `BaseStrictTable`
        raise AttributeError(
            f"{cls} is a strict table. Rows can only be defined explicitly by the `Model.create` method.")
# samudra/models/auth/pengguna.py
class Keizinan(BaseStrictTable):
    peranan = TextField(null=False, unique=True)
    baca = BooleanField(null=False)
    ubah = BooleanField(null=False)
    tambah = BooleanField(null=False)
    buang = BooleanField(null=False)

Penyelesaian

Boleh lakukan salah satu dari dua ini atau kedua-duanya sekali:

  1. Tambah kaedah menambah data Keizinan melalui API
  2. Buat satu fungsi agar setiap kali pangkalan data dicipta, satu baris data Keizinan dengan nilai RoleEnum.DEFAULT akan diisi. Jadi, pengguna-pengguna baharu akan dapat nilai RoleEnum.DEFAULT.

from samudra.

Related Issues (16)

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.